Client script to show specific values on catalog item

Souvick A
Tera Contributor

Hello All,

I have a requirement as below:

Variable category - option A and B

Variable sub category - options S1,S2,S3,S4

when option A selected , option S1 and S2 will be visible and on option B - option S3 and S4 will be visible.

Both these variables are select box type and options are choices configured.

Please help with the on change client script.

 

Regards

Souvick

1 ACCEPTED SOLUTION

Try this

 

 

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }
// Selective options on category
var cat = g_form.getValue('category');
alert('Value of:'+cat);
if (cat == 'A'){
  g_form.clearOptions('sub_category');
g_form.addOption('sub_category', 'S1', 'S1');
g_form.addOption('sub_category', 'S2', 'S2');
}
 else if (cat == 'B'){
  g_form.clearOptions('sub_category');
g_form.addOption('sub_category', 'S3', 'S3');
g_form.addOption('sub_category', 'S3', 'S3');
}
 }

 

-Anurag

View solution in original post

6 REPLIES 6

Anurag Tripathi
Mega Patron
Mega Patron

You probably don't need a client script, on the choice field add the dependent value

For S1 & S2 make the dependent value as A

For S3 & S4 make the dependent value as B

 

AnuragTripathi_0-1684851762032.png

 

-Anurag

The requirement is on the script so I would like to know the script for this solution.

KB18
Tera Guru
Tera Guru

Dear @Souvick A 

You have to check value of the Cat, base on that you have tom use g_form.addOptions and removeOption

 

Note: better solution to use dependent value in choice table.

 

Please feel to ask any questions in case any queries.

Please hit the thumb Icon and mark as correct in case I help you with your query!!!
- Kailas

Souvick A
Tera Contributor

Below is my onchange client sript. It is working for option A, but for option B it is showing all the options

Can I get help on this. Also , the choice table logic is new , so in order to configure that, what will be the table name for variables

 

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }
// Selective options on category
var cat = g_form.getValue('category');
alert('Value of:'+cat);
if (cat == 'A'){
g_form.getOption('sub_category', 'S1');
g_form.getOption('sub_category', 'S2');
g_form.removeOption('sub_category', 'S3');
g_form.removeOption('sub_category', 'S4');
}
 else if (cat == 'B'){
 g_form.getOption('sub_category', 'S3');
 g_form.getOption('sub_category', 'S4');
 g_form.removeOption('sub_category', 'S1');
 g_form.removeOption('sub_category', 'S2');
}
 }