I am trying to validate a form to check if the inputs are empty or not at THIS JSFIDDLE
I was able to validate the form successfully when I used the whole body of the validateEmpty() function directly inside the .submit() function but just to keep everthing organized I tried to put everything inside a function (validateEmpty()) and just call it through the .submit() function but for what ever reason the validation process is not working!
Here is the Code I have:
$(document).ready(function() {
function validateEmpty(){
var abort = false;
$("div.err").remove();
$(':input[required]').each(function() {
if ($(this).val()==='') {
$(this).parent().after('<div class="err">This is a Requierd Field</div>');
abort = true;
}
})
if (abort) { return false; } else { return true; }
}
$('#myform').submit(function() {
validateEmpty();
})
});
can you please let me know what I am doing wrong? Thanks