How can I make sure that the form will not be submitted if one of the checks is false?
$('#form').submit(function(){ validateForm1(); validateForm(document.forms['dpart2']); validateForm(document.forms['dpart3']); });
If the function returns false, the form will not be submitted.
$('#form').submit(function(){ return validateForm1() && validateForm(document.forms['dpart2']) && validateForm(document.forms['dpart3']); } });
$('#form').submit(function(){ return (validateForm1() && validateForm(document.forms['dpart2']) && validateForm(document.forms['dpart3'])) });
Basically, you return false in the event handler function.
, ... , , , , . , false, .
$("#myform").submit(function() { var ret = true; ret = validateForm1() && ret; ret = validateForm(document.forms['dpart2']) && ret ret = validateForm(document.forms['dpart3'])) && ret return ret; });
, .
validateForm (...) validateForm1() (true , ), :
$('#form').submit(function(){ if (!validateForm1() || !validateForm(document.forms['dpart2']) || !validateForm(document.forms['dpart3'])) { return false; } });
The thought that arises automatically: even if you have implemented a thorough check on the client side, be prepared to receive any incorrect request data on the server that you can imagine.
Client-side validation never allows you to validate a server. This is just a usability bonus.