Hey everyone, I've encountered an issue with my code. When testing each part individually, everything works fine. However, when all parts are combined and the first IF statement is reached, the form gets submitted without validating the others. Can anyone help me restructure my code so that it runs all IF statements before returning true?
Below is the code snippet:
if (this.element.find('#visitdate').length > 0) {
var dateParts = $('#tvisitdate').val().split('/');
var check = new Date(dateParts[2], dateParts[1]-1, dateParts[0], 0,0,0,0);
var d = new Date();
var today = new Date(d.getFullYear(), d.getMonth(), d.getDate());
if (today.getTime() > check.getTime() ) {
_errMsg = "Please enter a future visit date";
return false;
} else {
return true;
}
}
if (this.element.find('#birthdate').length > 0) {
var dateParts1 = $('#birthdate').val().split('/');
var check1 = new Date(dateParts1[2], dateParts1[1]-1, dateParts1[0], 0,0,0,0).getFullYear();
var today1 = new Date();
var year = today1.getFullYear();
if (check1 >= year) {
_errMsg = "Please enter a valid date of birthday";
return false;
} else {
return true;
}
}