Onchange of varaibles remove option is not working

1234567789hrebn
Tera Expert

Hello All,

i have created onchange client script to remove option based other variable but it is not working as expected please provide your inputs on it below is my scenario.

Two Variables of type select box A and B

A has two choices  x and y 

B has two choices p and q

if we select x under A only p has to display for B 

for y we need to display both values of B

i have created a script of onchange when we select x under A only one values is showing working fine but when changing back to y B has to display both values but it is not happening .

 

Please provide me with workaround 

11 REPLIES 11

Harshal Aditya
Mega Sage
Mega Sage

Hi,

Please use below on change  script

if(newValue=="x")

{

g_form.RemoveOption("B","p');

g_form.AddOption("B","q");

 

}

else

{

g_form.RemoveOption("B","q');

g_form.AddOption("B","p");

}

 

Hope this works

 

Regards

Vaibhav
Mega Guru

 

Hi,

 

As per your requirements try following onChange Client Script.

 

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

if(newValue == 'X'){
  g_form.removeOption('u_field_b','Q');
  g_form.addOption('u_field_b','P', 'P');
}


if(newValue == 'Y'){
  g_form.addOption('u_field_b','P', 'P'); 
  g_form.addOption('u_field_b','Q', 'Q');

}
}

 

If its helpfull mark it correct.

 

Regards,

 

Vaibhav Chaudhari