I am struggling with preventing my form from submitting if the user has not entered information or has entered it incorrectly. Despite having code in my JavaScript to handle this validation, when I click the submit button, the form still submits. I tried using code that I copied from another form validation script but it doesn't seem to be working for me.
Below is the snippet of code I added for the submit button:
var submitButton = document.querySelector('#submit');
submitButton.onclick = function(){
var nameIsValid = checkName();
var emailIsValid = checkEmail();
var passwordIsValid = checkPassword();
var valid = nameIsValid && emailIsValid && passwordIsValid;
// Prevent default action if 'valid' still equals false
return valid;
}
If you'd like to see the full code and test it out, you can access my fiddle at the following link: http://jsfiddle.net/pXLPv/