lundi 30 avril 2018

validating form entries before allowing to submit

Please help: New to this and I can't figure this out. Creating a registration form. The code must check all fields that they are not empty and user must enter password twice. Only after filling out all fields and password matches can the register button works.

If they click the button before filling out all fields they should be advised that fields are required.

Nothing is happening when I run the code.

This is what I have.

$ (function(){
    $('.btn').on('click'(function(){
        validateFormFName();
        validateFormLName();
        validateFormEmail();
        password();
    });
});

function validateFormFName() {
    var x = document.form["formtype"]["fname"].value;
    if (x == "") {
        alert("Name must be filled out");
        return false;
    }
    return true;
}

function validateFormLName() {
    var x = document.form["formtype"]["lname"].value;
    if (x == "") {
        alert("Name must be filled out");
        return false;
    }
    return true;
}

function validateFormEmail() {
    var x = document.form["formtype"]["email"].value;
    if (x == "") {
        alert("Your email is required");
        return false;
    }
    return true;
}


function password() {
    if (document.getElementById('psw1').value ==
        document.getElementById('psw2').value) {
        document.getElementById('register').disabled = false;
    } else {
        document.getElementById("register").disabled = true;
    }
}




Aucun commentaire:

Enregistrer un commentaire