removeOption and addOption

ceraulo
Mega Guru

Hello!

I have 2 variables X & Y.

Variable X is a Select Box with values A & B
Variable Y is a Select Box with values 1, 2, 3, 4, 5, 6

I want to achieve are:
When X = A, Y should only display 1, 2, 3
When X = B, Y should only display 4, 5, 6 

How to do this?
Should I create 2 catalog client scripts for X = A and X = B?

Please help!

Thank you!

 

 

1 ACCEPTED SOLUTION

Shrutika Surwad
Kilo Guru

Hey,

I did same requirement on my instance and it is working right

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

g_form.addOption('variable_y',1,1);
g_form.addOption('variable_y',2,2);
g_form.addOption('variable_y',3,3);
	
g_form.removeOption('variable_y',4,4);
g_form.removeOption('variable_y',5,5);
g_form.removeOption('variable_y',6,6);

}

else if(newValue == 'b'){
g_form.addOption('variable_y',4,4);
	g_form.addOption('variable_y',5,5);
	g_form.addOption('variable_y',6,6);
	
g_form.removeOption('variable_y',1,1);
g_form.removeOption('variable_y',2,2);
g_form.removeOption('variable_y',3,3);

}

   //Type appropriate comment here, and begin script below
   
}

find_real_file.png

find_real_file.png

 

Thanks,

Shrutika

View solution in original post

9 REPLIES 9

I have similar requirement. So without using addOption and removeOption  can we achieve in another way. ?

g_form.addOption
g_form.removeOption

 

Shrutika Surwad
Kilo Guru

Hey,

I did same requirement on my instance and it is working right

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

g_form.addOption('variable_y',1,1);
g_form.addOption('variable_y',2,2);
g_form.addOption('variable_y',3,3);
	
g_form.removeOption('variable_y',4,4);
g_form.removeOption('variable_y',5,5);
g_form.removeOption('variable_y',6,6);

}

else if(newValue == 'b'){
g_form.addOption('variable_y',4,4);
	g_form.addOption('variable_y',5,5);
	g_form.addOption('variable_y',6,6);
	
g_form.removeOption('variable_y',1,1);
g_form.removeOption('variable_y',2,2);
g_form.removeOption('variable_y',3,3);

}

   //Type appropriate comment here, and begin script below
   
}

find_real_file.png

find_real_file.png

 

Thanks,

Shrutika

hey,

 

Any updates?

If I have answered your question, please mark my response as correct so that others with the same question in the future can find it quickly and that it gets removed from the Unanswered list.

 

Thanks,

Shrutika

 

Thank you for the helpful solution Shrutika Surwade

without using addOption and removeOption  can we achieve in another way. ?

g_form.addOption
g_form.removeOption