Everything in my code works as it should except for the one function, which is invoked by the submit button. This function is meant to again go back through each of the validation functions before allowing the form to be submitted.
-
"the finalVd function, which is invoked by the submit button" - no it is not nor is it defined as onsubmit="return finalVd();" with in the <form> element.user2417483– user24174832016-11-06 02:45:51 +00:00Commented Nov 6, 2016 at 2:45
-
Doesn't my onclick below take care of this?Auborey– Auborey2016-11-06 02:57:29 +00:00Commented Nov 6, 2016 at 2:57
Add a comment
|
1 Answer
return true statement is missing in validation functions. if you not returning anything function will return undefined which will be resolved to false;
function nameValidator(name) {
var reg = /^[A-Z][a-z]+$/;
if (reg.test(name)) {
document.getElementById("firstName").style.background = "#8B008B";
return true;
} else {
document.getElementById("firstName").style.background = "#ff5050";
alert("Please capitalize the first letter of name");
return false;
}
}