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-31-2022 08:45 PM
On first two if checks you are comparing variable permit with capital 'A' and capital 'B', whereas on third if you are checking permit with small 'c'.
Can you give it a shot with following.
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);
}