How to create the dependency choices on choice variable

vinod6
Tera Contributor

In catalog items I have created two variables

 

1. Company Name---Type is choices

  1. Company A

  2. Company B

  3. Company C

 

2. Location ------Type is choice

  1. Hyderabad

 2.Bangalore

 3.chennai

 4.Pune

 5 Mumbai

 6.Delhi

 

Q:  i have selected the Company Name A Then Location vales shown the Hyderabad and Pune 

 

Could you please help any one. 

5 REPLIES 5

ARUN MANOJ
Tera Contributor

Hi @vinod6 ,

 

Please create two select box for Company and Location, then add the company name in the choice in variable company. Then create a selectbox for location. After that create a client script , Onchange for variable company .

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }

    //Type appropriate comment here, and begin script below
    if (newValue == 'company_A') { // For 1st choice only option 'A' is added
        g_form.addOption('location', 'Hyderabad', 'Hyderabad');
        //Fieldname,Nameofthechoice,value
        g_form.addOption('location', 'Pune', 'Pune');
        g_form.removeOption('location', 'Chennai', 'Chennai');
        g_form.removeOption('location', 'Bangalore', 'Bangalore');

    }
    else if (newValue == 'company_B') {                                       //For choice 2  option 'B', 'C' are shown
    g_form.addOption('location', 'Chennai', 'Chennai');
    g_form.addOption('location', 'Bangalore', 'Bangalore');
    g_form.removeOption('location', 'Hyderabad', 'Hyderabad');
    g_form.removeOption('location', 'Pune', 'Pune');
}
else{
 g_form.removeOption('location', 'Hyderabad', 'Hyderabad');
        g_form.removeOption('location', 'Pune', 'Pune');
        g_form.removeOption('location', 'Chennai', 'Chennai');
        g_form.removeOption('location', 'Bangalore', 'Bangalore');
}

}
 

Please mark this comment as Correct Answer/Helpful if it helped you.

Regards,

Arun Manoj