Forum Moderators: open
var error = 0;
var error_message = "Errors have occured during the process of your form!\nPlease make the following corrections:\n\n";
var bid = document.make_bid.customer_bid.value;
if (IsNumeric(bid) == false) {
error_message = error_message + "* Bid must be numeric!\n";
error = 1;
}
bid gets the value of document.make_bid.customer_bid.value ok but the statement "if (IsNumeric(bid) == false)" is failing whether the input field contents are numeric or not!
Any help gratefully received!
function IsNumeric(strString)
// check for valid numeric strings
{
var strValidChars = "0123456789.-";
var strChar;
var blnResult = true;
if (strString.length == 0) return false;
// test strString consists of valid characters listed above
for (i = 0; i < strString.length && blnResult == true; i++)
{
strChar = strString.charAt(i);
if (strValidChars.indexOf(strChar) == -1)
{
blnResult = false;
}
}
return blnResult;
}
Guessing that a negative Bid is not accepatble i would use this function instead
function isNumber(str){
numdecs = 0;
for (i = 0; i < str.length; i++){
mychar = str.charAt(i);
if ((mychar >= "0" && mychar <= "9") ¦¦ mychar == "."){
if (mychar == ".")
numdecs++;
}
else return false;
}
if (numdecs > 1)
return false;
return true;
}