Hide/Show select box variable based on the another select box variable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-29-2022 02:25 AM
I have 2 select box variables, for ex: First select box has values A,B,C and second select box has A1, A2 for A1 and B1, B2 for B. if I select first variable value is A, second variable should be visible and display with the A1, A2 values.
If select first variable value is C then second variable should not visible.
I have written onchange client script for this. Second variable values are showing according to the first variable selection but when i select the C value, second variable is not hiding.
Can any one help on this.
var permit = g_form.getValue("permit");
g_form.clearOptions("permit_type");
alert("permit:" + permit);
if (permit == "A") {
g_form.setDisplay("permit_type", true);
g_form.setMandatory("permit_type", true);
g_form.addOption("permit_type", "A1", "A1");
g_form.addOption("permit_type", "A2", "A2");
} else if (permit == "B") {
g_form.setDisplay("permit_type", true);
g_form.setMandatory("permit_type", true);
g_form.addOption("permit_type", "B1", "B1");
g_form.addOption("permit_type", "B2", "B2");
} else if (permit == "c") {
g_form.setMandatory("permit_type", false);
g_form.setDisplay("permit_type", true);
}
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-29-2022 02:30 AM
Hi,
are you sure any other script is showing it again?
share the complete script
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-29-2022 02:45 AM
I have hide the second variable with the onload client script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-29-2022 03:17 AM
Hi,
Did you debug using alert()?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-29-2022 02:31 AM
Hello,
Try replacing setDisplay with setVisible.
Also please check whether the isn't another client script that is running with a lower order(if the order is greater than yours it will run later and override your logic).
Hope this helps!
Tudor