Jump to content

Canceling Form Submissions


Compucles

Recommended Posts

It is usually called from the 'onsubmit' of the form not 'onclick' of submit button as someone could submit by pressing the 'Enter' button, and so bypass the 'onclick' event.<form onsubmit="return valdatethis();" action="whateverpage.php" method="post">return will cause the function to run but wait for return value of 'true' to proceed, or 'false' to not proceed because data is not valid.function valdatethis(){var isvalid=true;//run code to validate codeif(....){isvalid=false;}if(....) { isvalid=false; }//if any fails the validation code in the if conditions above, the value for varible 'isvalid' will be set to false, else it will remain as true.//now all you have to do is return this varible valuereturn isvalid;}more detailed example shown here, slightly different but does the same thing.http://www.w3schools.com/js/js_form_validation.asp

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...