Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-28-2003, 03:53 PM   PM User | #1
dotcomjr
New to the CF scene

 
Join Date: May 2003
Location: scotland, UK
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
dotcomjr is an unknown quantity at this point
Question 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.
dotcomjr is offline   Reply With Quote
Old 05-28-2003, 04:37 PM   PM User | #2
Spudhead
Senior Coder

 
Spudhead's Avatar
 
Join Date: Jun 2002
Location: London, UK
Posts: 1,856
Thanks: 8
Thanked 110 Times in 109 Posts
Spudhead is on a distinguished road
<ahem> The Javascript forum is over there -->

But you might want to have a look at the javascript function isNumeric() in the meantime...
Spudhead is offline   Reply With Quote
Old 05-29-2003, 08:44 AM   PM User | #3
joh6nn
wei wu wei


 
joh6nn's Avatar
 
Join Date: Jun 2002
Location: 72° W. 48' 57" , 41° N. 32' 04"
Posts: 1,887
Thanks: 0
Thanked 1 Time in 1 Post
joh6nn is an unknown quantity at this point
...

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; }
__________________
bluemood | devedge | devmo | MS Dev Library | WebMonkey | the Guide

i am a loser geek, crazy with an evil streak,
yes i do believe there is a violent thing inside of me.
joh6nn is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:36 PM.


Advertisement
Log in to turn off these ads.