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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

onSubmit submits no matter what!

Status
Not open for further replies.

keyer

Programmer
Aug 21, 2000
18
US
I'm using onSubmit() to validate a form, but it goes on to the next page no matter what I return.

My form:
<form name=&quot;OrderForm&quot; onSubmit&quot;isReady()&quot; action=&quot;go_on.html&quot;>


function isReady(){
if(isEmail(document.OrderForm.email.entry) == false) {
alert(&quot;Please enter a valid email address&quot;);
return false;
}


Even though it catches invalid Emails and puts up the alert (and since I never return true, it should NEVER submit), it always goes on and submits the &quot;action&quot; page. This is in Netscape 4.72-1
 
<form name=&quot;OrderForm&quot; onSubmit=&quot;return isReady()&quot; action=&quot;go_on.html&quot;>


 
Tried this. Same result, it still puts up the warning dialog, while behind the dialog, the next page (go_on.html) comes up!

BTW, this is Netscape 4.72 running on Linux.

 
I don't know that this will help but you are missing a brace in your function that you posted:

function isReady(){
if(isEmail(document.OrderForm.email.entry) == false) {
alert(&quot;Please enter a valid email address&quot;);
return false;
}


should be:

function isReady(){
if(isEmail(document.OrderForm.email.entry) == false) {
alert(&quot;Please enter a valid email address&quot;);
return false;
}
return true;
}


Good luck
-pete
 
Yes, thanks. I'll never know if it was a typo or what, because I took out the onSubmit(), and just used a button with onClick() calling the javascript validate function. Then that function does the submit itself without ever returning, using document.form.submit(). Seems to work so far.
 
I have found that alerting sometimes affects the submission of forms from a validating program. I would use an onclick event handler which either submits the form or not, and abandon the whole onsubmit handler entirely.

just a thought
jared@aauser.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top