For MUlTIPLE categories value apply IN CATALOG CLIENT SCRIPT?

angel kumari
Tera Contributor

Hi  Everybody,

I am stuck using these script.where is issue could any one suggest on its.

ONLY    new value== A is working all these

 

 

Thanks

Angel

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }
 
   //Type appropriate comment here, and begin script below
   var cat = g_form.getValue('category');
 if (newValue == 'A')
    {
        
        g_form.clearOptions('category');
        g_form.addOption('category', '', '-- None --');
        g_form.addOption('category', '1', '1');
        g_form.addOption('category', '2', '2');
 
        g_form.removeOption('category', '3', '3');
g_form.removeOption('category', '4', '4');
       g_form.removeOption('category', '5', '5');
        g_form.removeOption('category', '6', '6');
        g_form.removeOption('category', '7', '7');
 
    } else if (newValue == 'B') 
{
         g_form.clearOptions('category');
        g_form.addOption('category', '', '-- None --');
        g_form.addOption('category', '3', '3');
        g_form.addOption('category', '4', '4');
 
         g_form.removeOption('category', '1', '1');
g_form.removeOption('category', '2', '2');
       g_form.removeOption('category', '5', '5');
        g_form.removeOption('category', '6', '6');
        g_form.removeOption('category', '7', '7');
}
 
 else if (newValue == 'C') 
{
         g_form.clearOptions('category');
        g_form.addOption('category', '', '-- None --');
        g_form.addOption('category', '5', '5');
       
        g_form.removeOption('category', '1', '1');
g_form.removeOption('category', '2', '2');
       g_form.removeOption('category', '4', '4');
        g_form.removeOption('category', '6', '6');
        g_form.removeOption('category', '7', '7');
}
 
 else if (newValue == ' D') 
{
         g_form.clearOptions('category');
        g_form.addOption('category', '', '-- None --');
        g_form.addOption('category', '6', '6');
        g_form.addOption('category', '7', '7');
 
        g_form.removeOption('category', '1', '1');
g_form.removeOption('category', '2', '2');
       g_form.removeOption('category', '4', '4');
        g_form.removeOption('category', '5', '5');
        g_form.removeOption('category', '6', '6');
}
 
 else  (newValue == ' E') 
{
         g_form.clearOptions('category');
        g_form.addOption('category', '', '-- None --');
g_form.addOption('category', '1', '1');
        g_form.addOption('category', '2', '2');
        g_form.addOption('category', '3', '3');
        g_form.addOption('category', '4', '4');
        g_form.addOption('category', '5', '5');
        g_form.addOption('category', '6', '6');
        g_form.addOption('category', '7', '7');
4 REPLIES 4

Maddysunil
Kilo Sage

@angel kumari 

  1. In the else statement, you have used (newValue == ' E'), which should be else if (newValue == 'E'). You don't need parentheses for else statements.

  2. There's a duplicate removeOption for category '6' in the 'D' section.

 

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

    // Type appropriate comment here, and begin script below
    var cat = g_form.getValue('category');
    if (newValue == 'A') {
        g_form.clearOptions('category');
        g_form.addOption('category', '', '-- None --');
        g_form.addOption('category', '1', '1');
        g_form.addOption('category', '2', '2');
        g_form.removeOption('category', '3', '3');
        g_form.removeOption('category', '4', '4');
        g_form.removeOption('category', '5', '5');
        g_form.removeOption('category', '6', '6');
        g_form.removeOption('category', '7', '7');
    } else if (newValue == 'B') {
        g_form.clearOptions('category');
        g_form.addOption('category', '', '-- None --');
        g_form.addOption('category', '3', '3');
        g_form.addOption('category', '4', '4');
        g_form.removeOption('category', '1', '1');
        g_form.removeOption('category', '2', '2');
        g_form.removeOption('category', '5', '5');
        g_form.removeOption('category', '6', '6');
        g_form.removeOption('category', '7', '7');
    } else if (newValue == 'C') {
        g_form.clearOptions('category');
        g_form.addOption('category', '', '-- None --');
        g_form.addOption('category', '5', '5');
        g_form.removeOption('category', '1', '1');
        g_form.removeOption('category', '2', '2');
        g_form.removeOption('category', '4', '4');
        g_form.removeOption('category', '6', '6');
        g_form.removeOption('category', '7', '7');
    } else if (newValue == 'D') {
        g_form.clearOptions('category');
        g_form.addOption('category', '', '-- None --');
        g_form.addOption('category', '6', '6');
        g_form.addOption('category', '7', '7');
        g_form.removeOption('category', '1', '1');
        g_form.removeOption('category', '2', '2');
        g_form.removeOption('category', '3', '3');
        g_form.removeOption('category', '4', '4');
        g_form.removeOption('category', '5', '5');
    } else if (newValue == 'E') {
        g_form.clearOptions('category');
        g_form.addOption('category', '', '-- None --');
        g_form.addOption('category', '1', '1');
        g_form.addOption('category', '2', '2');
        g_form.addOption('category', '3', '3');
        g_form.addOption('category', '4', '4');
        g_form.addOption('category', '5', '5');
        g_form.addOption('category', '6', '6');
        g_form.addOption('category', '7', '7');
    }
}

 

  

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks

angel kumari
Tera Contributor

this is not working only first value which is  A work

@angel kumari 

Try to give some alerts in every if-else block and also change the new value to B or C or D while testing and observe the alerts. 

 

Amit Verma
Kilo Patron
Kilo Patron

Hi @angel kumari 

 

Could you please let me know on which variable you have kept the On-Change of this script ? If possible, can you please share some screenshots.

 

Thanks and Regards

Amit Verma


Please mark this response as correct and helpful if it assisted you with your question.