Click to See Complete Forum and Search --> : help w/ isNaN


IndyB
08-05-2003, 10:10 AM
I have this form field:
<input type="text" name="units" value="1" OnBlur="check_units()">

I need to us isNaN to make sure the users enter only numbers in this field.

To do that, I'm using this javascript:
function check_units()
{
var u = document.frmLookup.units.value;
if(isNaN(u) == true)
{ alert("That is not a valid number."); }
}

It works if I put a non number in the field then click out of the field. But then when I go back to put a number in the field and click out again, it still displays the alert, even though I've entered a number in the field. Can anyone see what I'm doing wrong here?

Charles
08-05-2003, 10:15 AM
I'm not exactly sure what you are doing wrong, but you can try:

<input type="text" name="units" value="1" onchange="if (isNaN(this.value)) {alert('That would not appear to be a number.'); this.value=''; this.focus()}">

IndyB
08-05-2003, 10:34 AM
Thanks Charles, that worked.