![]() | |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
What I am happening is that it alerts the message of all the errors because msg.length > 0, but then it submits the page!!! Even if I comment out the document.register.submit(), it still submits it. |
#3
| ||||||
| ||||||
|
|
I have the following: input type="image" src="images/submit.jpg" width="70" height="30" border="0" onclick="validateRegister()" / |
|
It is inside a form where: form action="register_submit.php" name="register" id="register" method="post" |
|
At the end of validateRegister() I have: if (msg.length > 0) { alert(msg); |
|
} else { document.register.submit(); |
|
} after having built the msg based upon any errors. (It starts with var msg = '' ![]() What I am happening is that it alerts the message of all the errors because msg.length > 0, but then it submits the page!!! Even if I comment out the document.register.submit(), it still submits it. |
|
How can it submit the page if not a single call is made to post and there is not button for submit? |
#4
| |||
| |||
|
|
sheldonlg <sheldonlg> wrote in news:ypmdnfVjedBd9K7VnZ2dnUVZ_gednZ2d (AT) giganews (DOT) com: I have the following: input type="image" src="images/submit.jpg" width="70" height="30" border="0" onclick="validateRegister()" / Remove the onclick on the image submit. It is inside a form where: form action="register_submit.php" name="register" id="register" method="post" Add onsubmit="return validateRegister();" to the form. At the end of validateRegister() I have: if (msg.length > 0) { alert(msg); add return false; } else { document.register.submit(); replace document.register.submit(); with return true; } after having built the msg based upon any errors. (It starts with var msg = '' ![]() What I am happening is that it alerts the message of all the errors because msg.length > 0, but then it submits the page!!! Even if I comment out the document.register.submit(), it still submits it. Input type="image" is your submit button. |
|
How can it submit the page if not a single call is made to post and there is not button for submit? Your submit button is the input image. |
|
Javascript validation is only a courtesy to the user, do validate on the server. |
#5
| |||
| |||
|
|
* sheldonlg wrote in comp.lang.javascript: What I am happening is that it alerts the message of all the errors because msg.length > 0, but then it submits the page!!! Even if I comment out the document.register.submit(), it still submits it. You have to prevent the default action of the submit event. Methods how to do that vary between browsers, one way to do it would be to call the .preventDefault() method on the event object where available. Another would be to `return false` from the code in the onsubmit attribute. |
#6
| |||
| |||
|
|
sheldonlg <sheldonlg> wrote in news:ypmdnfVjedBd9K7VnZ2dnUVZ_gednZ2d (AT) giganews (DOT) com: I have the following: input type="image" src="images/submit.jpg" width="70" height="30" border="0" onclick="validateRegister()" / Remove the onclick on the image submit. It is inside a form where: form action="register_submit.php" name="register" id="register" method="post" Add onsubmit="return validateRegister();" to the form. At the end of validateRegister() I have: if (msg.length > 0) { alert(msg); add return false; } else { document.register.submit(); replace document.register.submit(); with return true; |
#7
| |||
| |||
|
|
How is the default action being invoked? Nothing is labeled "submit" for a type and the submit() is not called. |
#8
| |||
| |||
|
|
sheldonlg escribió: How is the default action being invoked? Nothing is labeled "submit" for a type and the submit() is not called. input type="image" src="images/submit.jpg" width="70" height="30" border="0" onclick="validateRegister()" / http://www.w3.org/TR/html401/interac....html#h-17.4.1 |
![]() |
| Thread Tools | |
| Display Modes | |
| |