I have a submit button on a form for which I assigned a function to check required and visible fields. Upon encountering an empty field its supposed to add a class to a field, as well as display and error message. I have this jquery script:
$(".submitBtn").click(function(validateAll) {
if (validated = false) {
alert("!!!");
displayValidationErr();
} else {
$('#questionBody').submit();
}
});
function validateAll() {
var validated = true;
$('.form-control').filter('[required]:visible').each(function() {
if ($(this).val() === '') {
$(this).addClass("emptyRequired");
validated = false;
}
});
}
function displayValidationErr() {
$("#validationError").fadeTo(2000, 600).slideUp(600, function() {
$("#validationError").slideUp(600);
});
}
I am unable to pass a variable from "validateAll" function further upon clicking a button. Function works fine by itself, but not with if\else. I am very new to this stuff, so please be easy on me. :)
Thank you!