web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Pages / DOB required on check ...
Power Pages
Answered

DOB required on check - Javascript

(0) ShareShare
ReportReport
Posted on by 863

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);
      }});
Categories:
I have the same question (0)
  • Verified answer
    ctedesco3307 Profile Picture
    863 on at

    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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Pages

#1
Valantis Profile Picture

Valantis 65

#2
11manish Profile Picture

11manish 55

#3
Vish WR Profile Picture

Vish WR 29

Last 30 days Overall leaderboard