...

View Full Version : Return message if first value is correct?



jeanrigole
06-21-2010, 08:29 PM
Hi, I'm trying to figure out how to make this work and I'm stumped.

I wrote this code:


<script type=text/javascript>
function firstfunction();
{
if(document.form1.inputnumbers.value="55");
{
document.form1.outputstate.value="this is a number";
}
else if
{
document.form1.inputnumbers.value="never";
}
{
document.form1.outputstate.value="this is a number";
}
else
{
document.form1.outputstate.value="";
}
</script>


<form name="form1" method="post">
<input type="text" id="inputnumbers" name="inputnumbers";>
<input type="button"; value="Enter"; onclick="firstfunction()"><br><br>
<textarea id="outputstate"; name="outputstate"; cols=60; rows=10; style="border:1"; readonly;>


I'm trying to doing something really simple but I can't seem to make it work. I'm trying have the textarea display a certain message depending on if the first input box says a certain word or number. So like in the code, if the user types "55" or "never" in the first box, then the second box should say a certain message. Then I used the else statement so that if "55" or "never" is not entered, then the second box says nothing.

If you can spot my error or suggest a different way of going about writing the code, it would be very much appreciated. Thank you. :D

tomws
06-21-2010, 09:45 PM
That's like a picture of every elementary error possible, I think.

Look at these (among others):

<script type=text/javascript>
function firstfunction();
{
if(document.form1.inputnumbers.value="55");
{
document.form1.outputstate.value="this is a number";
}
else if
{
document.form1.inputnumbers.value="never";
}
{
document.form1.outputstate.value="this is a number";
}
else
{
document.form1.outputstate.value="";
}
//missing closing function brace
</script>

jeanrigole
06-21-2010, 10:03 PM
Hi, thanks for your help finding the errors. yes, I know I make lots of mistakes I am still learning. I corrected the errors in red, and tried several new ways of rewriting the code but it still isn't working. :confused:

tomws
06-21-2010, 10:19 PM
Show the corrected code.

By the way, your browser should be dumping notices for syntax errors like above.

jeanrigole
06-21-2010, 10:41 PM
This is the corrected code:


<script type=text/javascript>
function firstfunction()
{
if(document.form1.inputnumbers.value == "55")
{
document.form1.outputstate.value="this is a number";
}
else if(document.form1.inputnumbers.value="never")
{
document.form1.outputstate.value="this is a number";
}
else
{
document.form1.outputstate.value="";
}
}
</script>

<form name="form1" method="post">
<input type="text" id="inputnumbers" name="inputnumbers";>
<input type="button"; value="Enter"; onclick="firstfunction()"><br><br>
<textarea id="outputstate"; name="outputstate"; cols=60; rows=10; style="border:1"; readonly;>



It does something, just not what I want it to do.
I'm using http://htmledit.squarefree.com/ to edit the code, so it's not showing any syntax errors for me.

Philip M
06-21-2010, 10:52 PM
<script type=text/javascript>
function firstfunction() {
if(document.form1.inputnumbers.value == "55") {
document.form1.outputstate.value="this is a number";
}
else if(document.form1.inputnumbers.value == "never"){
document.form1.outputstate.value="this is a number";
}
else {
document.form1.outputstate.value="";
}
}
</script>

<form name="form1" method="post">
<input type="text" id="inputnumbers" name="inputnumbers";>
<input type="button"; value="Enter"; onclick="firstfunction()"><br><br>
<textarea id="outputstate"; name="outputstate"; cols=60; rows=10; style="border:1"; readonly;> </textarea>
</form>

Note that "Never" or "NEVER" != "never".

jeanrigole
06-21-2010, 11:04 PM
Thank you so much for the help, I almost had it, I just overlooked simple errors. thank again :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum