Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple onSubmit not verifying... 1

Status
Not open for further replies.

erinql

Programmer
Oct 19, 2001
13
0
0
US
This is copied directly from a DevShed example, and created in a file called submit.php.

Code:
<html>
<head>
<script>
function printMessage()
{
        alert(&quot;No, the answer is not &quot; + document.forms[0].answer.value
+ &quot;.\nEveryone knows the answer is 42.&quot;);
        return false;
}
</script>
</head>

<body>

<form action=&quot;submit.php&quot; method=&quot;post&quot; onSubmit=&quot;return
printMessage()&quot;> What is the answer? <br> <input type=&quot;text&quot;
name=&quot;answer&quot;> <br> <input type=&quot;submit&quot; value=&quot;Tell me the answer!&quot;>
</form>

</body>
</html>

I'm using IE 5.5, and everytime it submits, it simply comes back to submit.php - never gives me a message. Any idea why? Erin Quick-Laughlin
DBA, PHP/MySQL programmer
 
hmm. Not sure why that wouldn't work, but then again, i've never tried it liek taht. I usually do this.

<form action=&quot;submit.php&quot; method=&quot;post&quot;>
What is the answer? <br> <input type=&quot;text&quot; name=&quot;answer&quot;> <br>
<input type=&quot;button&quot; value=&quot;Tell me the answer!&quot; onClick=&quot;printMessage();&quot;>
</form>

Rick If I have helped you just click the first link below to let me know :)
 
In this case, it's pretty much just the onSubmit that's not working - I would just use onBlur and validate for each field, but I'm not sure how to let people get out of the field without fulfilling it's requirement.

So I decided to use onSubmit and do a collective function for all the individual verifications. But after running into a ton of trouble, I decided to run a simple one from DevShed, and that doesn't work either? Could it be a browser setting? Erin Quick-Laughlin
DBA, PHP/MySQL programmer
 
Here. This works fine:

<html>
<head>
<script>
function printMessage(){
if(document.forms[0].answer.value!=42){
alert(&quot;No, the answer is not &quot; + document.forms[0].answer.value + &quot;.\nEveryone knows the answer is 42.&quot;);
} else{
alert(&quot;Correct!!! The answer IS 42!&quot;);
}
}
</script>
</head>

<body>

<form onSubmit=&quot;printMessage();return false;&quot;>
What is the answer? <br>
<input type=&quot;text&quot; name=&quot;answer&quot;> <br>
<input type=&quot;submit&quot; value=&quot;Tell me the answer!&quot;>
</form>
</body>
</html>

Rick
If I have helped you just click the first link below to let me know :)
 
Thanks Rick! Erin Quick-Laughlin
DBA, PHP/MySQL programmer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top