Auborey Auborey - 1 year ago 97
Javascript Question

Javascript Form Validation Submit function

Everything in my code works as it should except for the

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. For example if you correctly fill the Name field, and then click submit, the
function appears to not go through each of the subsequent functions that are part of the if statement, to evaluate them. If you view the console logs I have put in place you can see this occurrence. The page and code can be viewed here:

Answer Source

return true statement is missing in validation functions. if you not returning anything function will return undefined which will be resolved to false;

function nameVd(name) {
        var reg = /^[A-Z][a-z]+$/;
        if (reg.test(name)) {
            document.getElementById("name").style.background = "#00cc00";
 return true;

        } else {
            document.getElementById("name").style.background = "#ff5050";
            alert("Name you entered must have first letter capitalized and the subsequent lowercase.");
            console.log("name false");
            return false;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download