I have 2 validators in my custom code - the email one works perfect but the DOB one I can't get to pass when I populate a date. The validator is supposed to check if DOB unknown is checked then a date is not needed in the DOB field. If DOB unknown is not checked then a date is needed I get the alert when DOB is unknown is NOT checked and DOB null but I can't get it to pass when I enter a DOB or if I check DOB unknown
$(document).ready(function () {
alert("todayemail2");
if (typeof (Page_Validators) == 'undefined') return;
// Create new validator
var newValidator = document.createElement('span');
newValidator.style.display = "none";
newValidator.id = "emailaddress1Validator";
newValidator.controltovalidate = "crb09_emailaddress1";
newValidator.errormessage = "<a href='#crb09_emailaddress1_label' referencecontrolid='crb09_emailaddress1 ' onclick='javascript:scrollToAndFocus(\"crb09_emailaddress1 _label\",\" crb09_emailaddress1 \");return false;'>Email is a required field.</a>";
newValidator.validationGroup = ""; // Set this if you have set ValidationGroup on the form
newValidator.initialvalue = "";
newValidator.evaluationfunction = function () {
var contactMethod = $("#crb09_preferredcontactmethodcode").val();
if (contactMethod != '476150001') return true; // check if contact method is not 'Email'.
// only require email address if preferred contact method is email.
var value = $("#crb09_emailaddress1").val();
if (value == null || value == "") {
return false;
} else {
return true;
}
};
// Add the new validator to the page validators array:
Page_Validators.push(newValidator);
{
alert("todaydob");
if (typeof (Page_Validators) == 'undefined') return;
// Create new validator
var newValidator = document.createElement('span');
newValidator.style.display = "none";
newValidator.id = "dobValidator";
newValidator.controltovalidate = "crb09_dateofbirth";
newValidator.errormessage = "<a href='#crb09_dateofbirth_label' referencecontrolid='crb09_dateofbirth ' onclick='javascript:scrollToAndFocus(\"crb09_dateofbirth _label\",\" crb09_dateofbirth \");return false;'>DOB is a required field.</a>";
newValidator.validationGroup = ""; // Set this if you have set ValidationGroup on the form
newValidator.initialvalue = "";
newValidator.evaluationfunction = function () {
var contactMethod = $("#crb09_dobunknown").is(':checked');
if (contactMethod = true) return false; // check if dobunknown checked.
// only require dob if unknown is not checked.
var value = $("#crb09_dateofbirth").val();
if (value == null || value == "" ) {
return false;
} else {
return true;
}
};
// Add the new validator to the page validators array:
Page_Validators.push(newValidator);
}});