Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    May 2003
    Location
    scotland, UK
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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.

  • #2
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    <ahem> The Javascript forum is over there -->

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

  • #3
    Senior Coder 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
    ...

    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •