I had to write some code where I had a lot of checkboxes and when a user selected a value on a dropdown then some would be shown and the rest would be hidden.
To do this I created 6 sections and placed the checkboxes in the correct section. When the user changed the dropdown I then displayed one of the sections and hide the others. This saved me writing the visible functionality for all the checkboxes (and there were loads – 60 plus).
Below is the Javascript which first reads the drop down and then based on the value it then displays a section and hides another. The real code had 6 sections which is why I used a switch statement rather than lots of IF and IFElse statements.
var mainJobType = Xrm.Page.getAttribute("meta_generaljobtype").getText(); switch (mainJobType) { case "Internal Works": Xrm.Page.ui.tabs.get("general").sections.get("InternalWorks").setVisible(true); Xrm.Page.ui.tabs.get("general").sections.get("ExternalWorks").setVisible(false); break; case "External Works": Xrm.Page.ui.tabs.get("general").sections.get("ExternalWorks").setVisible(true); Xrm.Page.ui.tabs.get("general").sections.get("InternalWorks").setVisible(false); break; default: Xrm.Page.ui.tabs.get("general").sections.get("InternalWorks").setVisible(false); Xrm.Page.ui.tabs.get("general").sections.get("ExternalWorks").setVisible(false); }