Hide/Show select box variable based on the another select box variable

manasa32
Tera Contributor

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);
    }

5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

are you sure any other script is showing it again?

share the complete script

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

I have hide the second variable with the onload client script.

Hi,

Did you debug using alert()?

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Tudor
Tera Guru

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