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 / Make Form field on pag...
Power Pages
Unanswered

Make Form field on page required based on another fields value

(0) ShareShare
ReportReport
Posted on by 863

Hey All - brand new to java scripting in portal pages.

 

I'm trying to say if DOB Unknown is set to No, which is the default setting for this field, make Victims Date of Birth Required. If DOB unknown is set to Yes, don't make it required. I think I figured out the function (make changes to my fields from a snippet I found online 

 

//New code DOB required
function makeDobRequired() {
    debugger;
    var KnowDob = $("#hd_victim_dob_unknown").val();
    if (KnowDob  == 0) //if dob is  known
    {
        makeRequired('cra83_dateofbirth');
           }
    else if (KnowDob  == 1) ////if dob is not known
    {
        makeNotRequired('cra83_dateofbirth');
    }
}
 
but don't I have to call the function on the change event for the DOB unknown field? (#hd_victim_dob_unknown) > Field name. 
 
How do I do that? also - does it matter where I put the function in my code? I put it in the beginning after my
document).ready(function ()
. there is no other code in the script with these fields.  The Victims Date of Birth is set to optional in dataverse. 
 
thx 
 
ctedesco3307_0-1695060288839.png

 

Categories:
I have the same question (0)
  • Lucas001 Profile Picture
    2,557 Super User 2026 Season 1 on at

    Hi @ctedesco3307,

     

    as you said the DoB column should be set to optional as it depends on another condition and will become required.

    I hope the code works as expected and I did not miss any bracket.

     

    The implementation should work when you use a similar code to:

     

     

    $(document).ready(function (){
    //Executed synchronically from top to bottom
    $(yourButtonDOBUnknown).on("click",function(){
     //Code to make your Field required.
     //Make it required by disabling your submit button.
     $(yourSubmitButton).attr("disabled",true)
    })
    $(yourDateValue).on("change",function() {
     //Check if input != null or != "" make buttom disabled false
     ($(yourDateValue).val() == "" || $(yourDateValue).val() == null) ? $(yourSubmitButton).attr("disabled",true) : $(yourSubmitButton).attr("disabled",true); 
    })
    })

     

     

     

    --------------------------------------------------------------------------------------

    Hope that helps.

    If the post solves your problem, please mark it as solution. If it helps, consider a thumbs up.

  • ctedesco3307 Profile Picture
    863 on at

    @Lucas001 Thanks for the reply.  I'm not sure if I updated this correctly. Can you confirm I only need to put in the column name where you have 

    $(yourButtonDOBUnknown)

     

    etc? 

     

    Also - how do I find the control name for the submit button? This is OOB Power Pages and it seems really hard to find the id's here on an inspect ....  I don't know what the oob name is of the control. 

    ctedesco3307_1-1695234684051.png

     

     

     

    Here is my mods to your code.  Thx - also there does appear to be a missing bracket - where does it go? I put it on the end but it didn't like it 

     

    $(document).ready(function {
    //Executed synchronically from top to bottom
    $(crb09_DOBUnknown).on("click",function(){
    //Code to make your Field required.
    //Make it required by disabling your submit button.
    $(yourSubmitButton).attr("disabled",true)
    })
    $(crb09_DateofBirth).on("change",function() {
    //Check if input != null or != "" make buttom disabled false
    ($(crb09_DateofBirth).val() == "" || $(crb09_DateofBirth).val() == null) ? $(yourSubmitButton).attr("disabled",true) : $(yourSubmitButton).attr("disabled",true);
    })
    });


     

    ctedesco3307_0-1695234507082.png

     

     

     

  • Lucas001 Profile Picture
    2,557 Super User 2026 Season 1 on at

    Hi @ctedesco3307,

     

    you will have to change all the ...your... jquery selectors, not only the one you mentioned.

    TO get the Ids and in some cases the css path, use the page in preview, not inside the portal management app. That way you will easily get your selectors.

     

    There were () missing in my code - I fixed it. In the future I propose using VS Code and pasting the code there - it mostly shows where the error occurs.

     

    Hope that helps.

    If you have any more problems, feel free to ask.

  • ctedesco3307 Profile Picture
    863 on at

    @Lucas001 if you look at my image I am in preview. The ID of the submit button is not visible. I did all the other thigs you mentioned already. 

  • Lucas001 Profile Picture
    2,557 Super User 2026 Season 1 on at

    Hi @ctedesco3307,

     

    as we are using a newer jQuery in Power Pages, could you follow that thread: https://stackoverflow.com/questions/6048022/jquery-attrdisabled-disabled-not-working-in-chrome

    and change the .attr to .prop?

     

    If the Id is not showing you can still use a class, easiest way is to use the chrome dev tools and copy the css selector. Test to change the .text() for example by executing jQuery inside the console.

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 53

#3
Vish WR Profile Picture

Vish WR 29

Last 30 days Overall leaderboard