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 5 of 5
  1. #1
    New Coder
    Join Date
    Dec 2012
    Posts
    11
    Thanks
    6
    Thanked 0 Times in 0 Posts

    How to get word variables[CODE]

    this is the current code
    <html>
    <head>
    <title>Myscript</title>
    <script type="text/javascript">

    function checkOranges(numOranges)
    {
    if (numOranges == hi)
    {
    alert("hai");
    }
    }

    </script>
    </head>
    <body>
    <h3> How many Oranges did you eat? </h3>
    <form method="POST" name="orangesform"
    onSubmit="checkOranges(document.orangesform.numOranges.value);">
    <input type="text" name="numOranges" id=numOranges />
    <input type="Submit" name="Submit" />

    </form>



    </body>
    </html>
    I'm using numOranges becuase I am borrowing from the lifehacker tutorial to try and get an idea of what im doing. Basically what I want to happen is when you type hi into the submission box and hit submit, the alert "hai" will come up, but I can't seem to accomplish this. Help please?
    Last edited by hossaim; 12-05-2012 at 09:55 PM.

  • #2
    Regular Coder
    Join Date
    May 2012
    Location
    France
    Posts
    224
    Thanks
    0
    Thanked 32 Times in 30 Posts
    Your function is not define the curly brakets are not closed
    Code:
    function checkOranges(numOranges)
       {// begin function
          if (numOranges == hi)
             {// begin if
                alert("hai");
             }// end if
       }//end function

  • #3
    New Coder
    Join Date
    Dec 2012
    Posts
    11
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by 007julien View Post
    Your function is not define the curly brakets are not closed
    Code:
    function checkOranges(numOranges)
       {// begin function
          if (numOranges == hi)
             {// begin if
                alert("hai");
             }// end if
       }//end function
    I put that in but it's still just doing nothing once i hit the submit button.

  • #4
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    You are referencing hi as a variable, not the "hi" string it should be.

    if(numOranges == "hi")
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • Users who have thanked WolfShade for this post:

    hossaim (12-05-2012)

  • #5
    New Coder
    Join Date
    Dec 2012
    Posts
    11
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by WolfShade View Post
    You are referencing hi as a variable, not the "hi" string it should be.

    if(numOranges == "hi")
    That fixed it. Thank you!


  •  

    Posting Permissions

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