Go Back   CodingForums.com > :: Client side development > JavaScript programming

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 12-05-2012, 09:35 PM   PM User | #1
hossaim
New Coder

 
Join Date: Dec 2012
Posts: 11
Thanks: 6
Thanked 0 Times in 0 Posts
hossaim is an unknown quantity at this point
How to get word variables[CODE]

this is the current code
Quote:
<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..
hossaim is offline   Reply With Quote
Old 12-05-2012, 09:43 PM   PM User | #2
007julien
Regular Coder

 
Join Date: May 2012
Location: France
Posts: 115
Thanks: 0
Thanked 17 Times in 15 Posts
007julien is an unknown quantity at this point
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
007julien is offline   Reply With Quote
Old 12-05-2012, 09:48 PM   PM User | #3
hossaim
New Coder

 
Join Date: Dec 2012
Posts: 11
Thanks: 6
Thanked 0 Times in 0 Posts
hossaim is an unknown quantity at this point
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.
hossaim is offline   Reply With Quote
Old 12-05-2012, 09:50 PM   PM User | #4
WolfShade
Regular Coder

 
Join Date: Apr 2012
Location: St. Louis, MO, USA
Posts: 952
Thanks: 7
Thanked 98 Times in 98 Posts
WolfShade is an unknown quantity at this point
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".
WolfShade is offline   Reply With Quote
Users who have thanked WolfShade for this post:
hossaim (12-05-2012)
Old 12-05-2012, 09:55 PM   PM User | #5
hossaim
New Coder

 
Join Date: Dec 2012
Posts: 11
Thanks: 6
Thanked 0 Times in 0 Posts
hossaim is an unknown quantity at this point
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!
hossaim 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 05:20 AM.


Advertisement
Log in to turn off these ads.