Helpful Information
 
 
Category: Java and JSP
javaScript, can i have some help please?

I am writing a calculator and need to have a cheak in so that the user has to input data into all the required fields. i have got as far as getting it to display an alert if the field does not have a specific value in it, but i was wondering if there was anyone out there who knows what the code is to get it to only come up if there is not a number input into the field. here is what i have come up with so far.

if (var1="piece i require")
{alert ("Please enter number for (a)");
}
else
{document.form1.Answer.value=result;
}

if (var2="piece i require")
{alert ("please enter number for (b)");
}
else
{document.form1.Answer.value=result;
}

Thank you for you help.
p.s. if you need the whole code, just ask.

<ahem> The Javascript forum is over there -->

But you might want to have a look at the javascript function isNumeric() in the meantime...

...

to the very best of my knowledge, there is no isNumeric function in javascript. there's isNaN, though, which will return true if the argument its passed isn't a number.

try this:

if (isNan(var1)) { alert ("Please enter number for (a)");}
else { document.form1.Answer.value = result; }

if (isNaN(var2)) { alert ("please enter number for (b)"); }
else { document.form1.Answer.value = result; }










privacy (GDPR)