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 / Multichoice show / hid...
Power Pages
Unanswered

Multichoice show / hide javascript not working

(0) ShareShare
ReportReport
Posted on by 32

I am trying to set a field show/hide, required/not required based on the value populated in a multiselect field. The code works fine when the field is a single drop down. Code is being entered into power custom javascript on portal form. Any advice welcome.

 

$(document).ready(function() {

  $("#replacement").click(SetFieldsVisiblityQB6);

  $("#replacement").click();

});

function SetFieldsVisibilityQB6() {

  var selectedValue = $("#replacement").val();

  if (selectedValue != null && selectedValue == "100000001")

  {

    $("#boughtin_label").closest("tr").show();

    $("#boughtin").prop("required",true).closest("tr").show();

  }

  else

  {

    $("#boughtin_label").closest("tr").hide();

    $("#boughtin").prop("required",false).closest("tr").hide();

  }

}

 

Categories:
I have the same question (0)
  • Saud Ali Profile Picture
    812 Super User 2024 Season 1 on at

    Hi @ahilisa ,

     

    In case of multiselect option set you will get an array of selected values. What you can do is loop through the list of selected items and then compare the same way you're doing above. You above code is manage only single value but you need to handle multiple.

     

    Here is an example, how I did it:

     

    //Assuming my multiselect column name is Document List
    
    var multiselectVal = $("#pp_documentchecklist").val();
    var parsedMultiselectVal = JSON.parse(multiselectVal);
    
    for (var i = 0; i < parsedMultiselectVal .length; i++) {
     var value = parsedMultiselectVal [i]['Value'];
     console.log(value); //This is the list of all selected values
    }

     

    Sorry, for rough example through, but I hope it helps. Feel free to ask if you have any questions. 

     

    Thanks,

    Saud

     

    If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.

  • Surendran Ravindran Profile Picture
    212 on at

    Hi @ahilisa ,

     

    The line $("replacement").click(); seems to be missing the "#" to correctly select the element by ID. It should be $("#replacement").click();. Also, make sure that the element with ID "replacement" exists in your HTML.

     

    Regards

    Surendran Ravindran

     

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

    Hope that helps.

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

  • ahilisa Profile Picture
    32 on at

    Hi Saud, 

     

    Yes the issue is I was not sure how to handle multiple values. 

     

    Where is my code does your example go into? 

     

    thanks

    Lisa 

  • ahilisa Profile Picture
    32 on at

    thank you, that was a typo, but it hasnt worked, any other advice much appreciated. 

  • oliver.rodrigues Profile Picture
    9,482 Most Valuable Professional on at

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Pages

#1
Fubar Profile Picture

Fubar 33 Super User 2026 Season 1

#2
sannavajjala87 Profile Picture

sannavajjala87 32 Super User 2026 Season 2

#3
Mohsin Ali Profile Picture

Mohsin Ali 25

Last 30 days Overall leaderboard