I'm trying to call multiple JavaScript functions. It submits even though my functions return false. I receive the alert messages but it submits anyway.
This is my form.
<form name="myform" id="myform" action="receipt.html" method="post" onSubmit="return allValidation();">
-
You aren't using the return values.SLaks– SLaks2015年11月29日 15:40:20 +00:00Commented Nov 29, 2015 at 15:40
-
@SLaks I've edited the functions now. Something like that?dafyddgj– dafyddgj2015年11月29日 16:12:10 +00:00Commented Nov 29, 2015 at 16:12
4 Answers 4
You aren't returning anything in allValidation, so that it will continue to next method execution. Try this,
function allValidation() {
return validateForm() && selectCountry() && validateEmail();
}
4 Comments
return true value(as last line) in all validateForm(), selectCountry(), validateEmail() methods.return true should be without bracket. I have modified your question with my suggestion. Hope this will resolve your issue. Keep trying..You can use multiple functions and then and their results to get final validation. and also add return true statements in all functions where validation is successful
function allValidation()
{
return (validateForm() && selectCountry() && validateEmail());
}
Comments
It's because your function always return true no matter what values return the validateForm() selectCountry() and validateEmail() functions.
Change your allValidation() function like this:
function allValidation()
{
return validateForm() && selectCountry() && validateEmail();
}
2 Comments
return validateForm() && selectCountry() && validateEmail(); or return (validateForm() && selectCountry() && validateEmail()); has exactly the same effect.function allValidation(){
return validateForm() && selectCountry() && validateEmail();
}