...

View Full Version : Resolved How to get word variables[CODE]



hossaim
12-05-2012, 10:35 PM
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?

007julien
12-05-2012, 10:43 PM
Your function is not define the curly brakets are not closed

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

hossaim
12-05-2012, 10:48 PM
Your function is not define the curly brakets are not closed

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.

WolfShade
12-05-2012, 10:50 PM
You are referencing hi as a variable, not the "hi" string it should be.

if(numOranges == "hi")

hossaim
12-05-2012, 10:55 PM
You are referencing hi as a variable, not the "hi" string it should be.

if(numOranges == "hi")

That fixed it. Thank you!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum