Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Pages - Power Apps Portals
Unanswered

Show/Hide fields based on a Yes/No field selection with javascript

(0) ShareShare
ReportReport
Posted on by 50

Hi community, thanks for the great support you all provide.

 

Could you please assist with a sample of how to show/hide based on a Yes/No field selection? Here is my sample I've been trying in various ways without success.

 

 

$(document).ready(function () {
 $("#myYesNoField").change(onChangeEvent);
 onChangeEvent();
});

function onChangeEvent() {
 var varChange = $('#myYesNoField').val();
 
 if (varChange == 1) {
 
 $('#myFieldName').parent().parent().show();
 }
 else {
 $('#myFieldName').parent().parent().hide();
 }
}

 

 

Thanks so much in advance!!

  • oliver.rodrigues Profile Picture
    9,342 Most Valuable Professional on at
    Re: Show/Hide fields based on a Yes/No field selection with javascript

    Hi, if you are using radio buttons, probably the issue is when reading the value of the field

    try something like:

     var selectedValue = $("#<COLUMN>").find("input[type='radio']:checked").val();
    
  • DylanR Profile Picture
    50 on at
    Re: Show/Hide fields based on a Yes/No field selection with javascript

    Hi again, I changed the format to dropdown list and it now works. 

    Neither checkbox or radio button works, which doesn't make sense. Thanks for your assistance.

  • DylanR Profile Picture
    50 on at
    Re: Show/Hide fields based on a Yes/No field selection with javascript

    It's Radio Buttons @OliverRodrigues 

     

    Should I try a different format?

     

    DylanR_0-1628263293448.png

     

     

  • oliver.rodrigues Profile Picture
    9,342 Most Valuable Professional on at
    Re: Show/Hide fields based on a Yes/No field selection with javascript

    can you add a snapshot of your form? how are you rendering your Yes/No?

    if it via Radio Buttons? dropdown? checkbox?

  • DylanR Profile Picture
    50 on at
    Re: Show/Hide fields based on a Yes/No field selection with javascript

    Thank you @OliverRodrigues for your suggestion.
    I have tried what you suggested (and many other variations) without success. The event does not trigger when the TwoOption field changes its value.


    Here is the actual code I've tried which isn't working. I would really appreciate if you could edit as needed.

    Many thanks!

    $(document).ready(function () {
     onChangeEvent();
     $('#new_accountregulated').on("change", onChangeEvent);
    });
    
    function onChangeEvent() {
     var varChange = $('#new_accountregulated').val();
     if (varChange == 1) {
    		$('#new_regulatedby').closest("td").find("div.control, div.info").show();
     }
     else {
    		$('#new_regulatedby').closest("td").find("div.control, div.info").hide();
     }
    }
  • oliver.rodrigues Profile Picture
    9,342 Most Valuable Professional on at
    Re: Show/Hide fields based on a Yes/No field selection with javascript

    hi @DylanR instead of using:

     $("#myYesNoField").change(onChangeEvent);
    

    can you try?:

     $("#myYesNoField").on("change", onChangeEvent);
    

     

  • DylanR Profile Picture
    50 on at
    Re: Show/Hide fields based on a Yes/No field selection with javascript

    Hi @OOlashyn 
    Thanks so much for the feedback. I had previously seen the post from @OliverRodrigues but couldn't get the script to work.

     

    My challenge is not the show / hide part (as I'm doing this already for other fields). My issue is triggering the script when the Yes/No field value is changed.

     

    This is the part of the script that doesn't seem to be correct.

    function onChangeEvent() {
     var varChange = $('#myYesNoField').val();
     if (varChange == 1) 

     

    I've tried changing if (varChange == 1)  to if (varChange == true)  or if (varChange === "Yes") and none of them work.

     

  • OOlashyn Profile Picture
    3,496 Most Valuable Professional on at
    Re: Show/Hide fields based on a Yes/No field selection with javascript

    Hi @DylanR,

    Check this article from @OliverRodrigues on how to show hide fields with code.

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

Paul Stork – Community Spotlight

We are honored to recognize Paul Stork as our July 2025 Community…

Congratulations to the June 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
Lucas001 Profile Picture

Lucas001 60 Super User 2025 Season 1

#2
Fubar Profile Picture

Fubar 55 Super User 2025 Season 1

#3
surya narayanan Profile Picture

surya narayanan 35