Results 1 to 4 of 4

Thread: need help validating inputs

  1. #1
    Join Date
    Feb 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default need help validating inputs

    hey everyone. i am taking a javascript class, and am having some trouble with an assignment. The assignment wants me to ask a user to input 3 values and test if they can make a triangle.

    The part where I am stuck is when I am validating the user input to see if they are numbers. I use the "isNan" function. Anyways I copy pasted my code below. Can anyone tell me where I am going wrong? Thanks!

    The code follows below:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

    <head>

    <title> Assignment 2</title>


    <script type="text/javascript">
    <!--HIDE FROM INCOMPATIBLE BROWSERS

    function isNumber(element) {
    var testNumber = isNan(element);
    if (testNumber == true) {
    window.alert("Please enter a number!");
    return false;
    }
    }


    // STOP HIDING FROM INCOMPATIBLE BROWSERS -->
    </script>


    </head>

    <body>


    <h1>Assignment 2</h1>
    <p>Enter 3 numbers that you would like to test for below.</p>

    <form action="FormProcessor.html" method="get" enctype="application/x-www-form-urlencoded">

    <p>Number 1: <input type="text" name="first_number" size="10" onchange="return isNumber(this.value);" /></p>
    <p>Number 2: <input type="text" name="second_number" size="10" onchange="return isNumber(this.value);" /></p>
    <p>Number 3: <input type="text" name="third_number" size="10" onchange="return isNumber(this.value);" /></p>


    </form>


    </body>
    </html>

  2. #2
    Join Date
    Feb 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Oh yea, please remember that I am a newbie to this. I would appreciate it if you tried to keep your explanations as simple as possible. Thanks again!

  3. #3
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    The problem seems to be the following item:
    Code:
    var testNumber = isNan(element);
    The function name is not isNan but isNaN
    Code:
    var testNumber = isNaN(element);
    If you correct this I think it should work

  4. #4
    Join Date
    Jun 2007
    Posts
    543
    Thanks
    3
    Thanked 78 Times in 78 Posts
    Blog Entries
    1

    Default

    do you also need to help with seeing if the numbers can be angles for a triangle?
    [Jasme Library (Javascript Motion Effects)] My Site
    /\/\@§†ê® §©®¡þ† /\/\@|{ê®
    There are 10 kinds of people in the world, those that understand binary and those that don't.

Bookmarks

Posting Permissions

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