Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Pages - Customize & Extend
Answered

DOB required on check - Javascript

(0) ShareShare
ReportReport
Posted on by 623

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 

 

ctedesco3307_0-1696339914204.pngctedesco3307_1-1696339947999.png

 


 

 $(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&colon;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&colon;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);
      }});
  • Verified answer
    ctedesco3307 Profile Picture
    623 on at
    Re: DOB required on check - Javascript

    I got it 

     


    $(document).ready(function () {
    alert("todaymm1");
     
    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&colon;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 dobMethod = $("#crb09_dobunknown").is(':checked');
    if (dobMethod != false) return true; // 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);


    });

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Michael Gernaey – Community Spotlight

We are honored to recognize Michael Gernaey as our June 2025 Community…

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > Power Pages

#1
Fubar Profile Picture

Fubar 69 Super User 2025 Season 1

#2
oliver.rodrigues Profile Picture

oliver.rodrigues 49 Most Valuable Professional

#3
Jon Unzueta Profile Picture

Jon Unzueta 43

Featured topics