Click to See Complete Forum and Search --> : Check for only numbers


Jmicoli
05-14-2003, 09:39 PM
I am new to javascripting and I am trying to write the following code but it doesn't work. Where am I going wrong??? (besides trying to write code)



<html>
<head>


<script type="text/javascript" language="JavaScript">
</script>

</head>
<br>
<body>
<form name="myform">
<input type="text" name="input" value=""><br>

<input type="button" value="Click here"
onClick="var x=document.myform.input.value;
while (x <= 10){
(isNAN (x)==true)
{
alert('please enter a number');

}
document.write('The number is ' + x + <br>');
x++
}">
</form>
</body>
</html>
:confused:

goofball
05-15-2003, 08:12 AM
I agree -everyone has their own methods. Here's one I like to use. It has no alert box, but just disallows any non-number chars from being entered in the first place.

<input type="text" name="input"
onKeyUp="this.value=this.value.replace(/\D/g,'');">

Hope you like it, too!

Jmicoli
05-15-2003, 03:48 PM
Thanks for the ideas but I'm really trying to get the while loop to work.:confused:

Jmicoli
05-16-2003, 08:48 AM
Thanks Dave - I understand.;)