Help needed with dropdown values in client script

Snehal13
Kilo Sage

I have a dropdown with some values. I want to show different values based on the type of type.

 

If user choose type as India, show 3 values in dependant dropdown.

If user choose type as Onsite, show 2 values in dependant dropdown .

 

How to hide and show based on the selection

3 REPLIES 3

Samaksh Wani
Giga Sage
Giga Sage

Hello @Snehal13 

 

You need to write a onChange Client Script :-

 

 

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue == '') {
          return;
    }
   
   var loc= g_form.getValue('fieldname');
   if(loc == 'India'){
    g_form.clearOptions(<fieldName>);
    g_form.addOption(<fieldName>, <choiceValue>, <choiceLabel>, <targetIndex>);
   g_form.addOption(<fieldName>, <choiceValue>, <choiceLabel>, <targetIndex>);
   g_form.addOption(<fieldName>, <choiceValue>, <choiceLabel>, <targetIndex>);
   }
  if(loc == 'Onsite){
  g_form.clearOptions(<fieldName>);
 g_form.addOption(<fieldName>, <choiceValue>, <choiceLabel>, <targetIndex>);
 g_form.addOption(<fieldName>, <choiceValue>, <choiceLabel>, <targetIndex>);
 }
   
}

 

 

 

Plz Mark my Solution as Accept and Give me thumbs up, if you find it helpful.

 

Regards,

Samaksh

Harish Bainsla
Kilo Patron
Kilo Patron

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

//Type appropriate comment here, and begin script below
var a = g_form.getValue('u_choice_1');

if (a == 'jharkhand') {
g_form.clearOptions('u_choice_3');
g_form.addOption('u_choice_3', 'ranchi', 'Ranchi');
g_form.addOption('u_choice_3', 'deoghar', 'Deoghar');

}
if (a == 'karnataka') {
g_form.clearOptions('u_choice_3');
g_form.addOption('u_choice_3', 'bangalore', 'Bangalore');
g_form.addOption('u_choice_3', 'mysore', 'Mysore');

}
if (a == 'maharastra') {
g_form.clearOptions('u_choice_3');
g_form.addOption('u_choice_3', 'pune', 'Pune');
g_form.addOption('u_choice_3', 'mumbai', 'Mumbai');

}
}

Samaksh Wani
Giga Sage
Giga Sage

Hello @Snehal13 

 

Plz Mark my Solution as Accept and Give me thumbs up, if you find it helpful and close the thread. 

 

Regards,

Samaksh