0

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.

2
  • "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. Commented Nov 6, 2016 at 2:45
  • Doesn't my onclick below take care of this? Commented Nov 6, 2016 at 2:57

1 Answer 1

1

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;
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.