...

View Full Version : How to check for Nan whilst checking for "" aswell



Scott.Atkinson
09-24-2011, 11:21 AM
Hi All,

i have a javascript function which i pass 3 fields to which then check to see if they are empty but the two other fields txtDeveloperDetailEstimate and TxtAldonTaskNumber are numeric and i need to check for != NaN but when i fill something in to the comment area it comes back as red even though there is some text in it, how can i check for the numeric values of the other two without interupting the first check for comments etc?




var DevFieldCheck = Array('MainDisplayContentChange_txtDeveloperComment', 'MainDisplayContentChange_txtDeveloperDetailEstimate', 'MainDisplayContentChange_txtAldonTaskNumber');
var obj;
function DevItemCheck(windowname) {
for (var i = 0; i < DevFieldCheck.length; i++) {
obj = document.getElementById(DevFieldCheck[i]);

if (obj.value == "" || obj.value == 0 || obj.value != NaN)
{
obj.style.backgroundColor = "#B20635";
return false;
}

}
Businesspopup(windowname)
}



Any help will be highly appreciated.
**Update**
Iv tried this aswell but it still turns red when there is a number in there :(



var DevFieldCheck = Array('MainDisplayContentChange_txtDeveloperComment');
var obj;
function DevItemCheck(windowname)
{
for (var i = 0; i < DevFieldCheck.length; i++)
{
obj = document.getElementById(DevFieldCheck[i]);

if (obj.value == "" || obj.value == 0) {
obj.style.backgroundColor = "#B20635";
return false;
}
}



if (document.getElementById('MainDisplayContentChange_txtDeveloperDetailEstimate').value = NaN)
{
document.getElementById('MainDisplayContentChange_txtDeveloperDetailEstimate').style.backgroundColor = "#B20635";
return false;
}
if (document.getElementById('MainDisplayContentChange_txtAldonTaskNumber').value == NaN)
{
document.getElementById('MainDisplayContentChange_txtAldonTaskNumber').style.backgroundColor = "#B20635";
return false;
}
AnotherDevpopup(windowname)
}



Im aware i have one line with "=" and the other with "==" i was testing both out...to see if it made a difference

vwphillips
09-24-2011, 01:12 PM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<title></title>
<script type="text/javascript">
/*<![CDATA[*/
var DevFieldCheck = Array('MainDisplayContentChange_txtDeveloperComment', 'MainDisplayContentChange_txtDeveloperDetailEstimate', 'MainDisplayContentChange_txtAldonTaskNumber');

function DevItemCheck(windowname) {
for (var obj,reg=new RegExp('\\bnumber\\b'),i = 0; i < DevFieldCheck.length; i++) {
obj = document.getElementById(DevFieldCheck[i]);

if (!obj.value||(reg.test(obj.className)&&isNaN(obj.value)))
{
obj.style.backgroundColor = "#B20635";
// return false;
}

}
// Businesspopup(windowname)
}

/*]]>*/
</script>
</head>

<body>
<input name="" id="MainDisplayContentChange_txtDeveloperComment" />
<input name="" class="myclass number" id="MainDisplayContentChange_txtDeveloperDetailEstimate" />
<input name="" class="number" id="MainDisplayContentChange_txtAldonTaskNumber" />
<input type="button" name="" value="TEST" onmouseup="DevItemCheck();"/>
</body>

</html>

Scott.Atkinson
09-24-2011, 03:18 PM
Excellent thanks!! Works a charm!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum