...

javaScript, can i have some help please?

dotcomjr
05-28-2003, 03:53 PM
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.

Spudhead
05-28-2003, 04:37 PM
<ahem> The Javascript forum is over there -->

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

joh6nn
05-29-2003, 08:44 AM
...

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; }



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum