How can I make sure the form won't submit if one of the validations is false?
$('#form').submit(function(){
validateForm1();
validateForm(document.forms['dpart2']);
validateForm(document.forms['dpart3']);
});
How can I make sure the form won't submit if one of the validations is false?
$('#form').submit(function(){
validateForm1();
validateForm(document.forms['dpart2']);
validateForm(document.forms['dpart3']);
});
If validateForm(...) and validateForm1() return a boolean (true means that no validation error occurred), then you try to do that :
$('#form').submit(function(){
if (!validateForm1() || !validateForm(document.forms['dpart2']) || !validateForm(document.forms['dpart3'])) {
return false;
}
});
If the function returns false, form won't 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.
A thought that comes up automatically: Even if you implemented thorough client side validation be prepared to receive any invalid request data on the server that you can possibly imagine.
Client-side validation never keeps you from server-side validation. It is just a bonus in usability.