showing items in Select box

Walter Toney
Tera Expert

Good Day Team,

 

I have a Select Box (Items)with 40 different options (dont) ask my why. the requirement i have is to narrow the list based on another field (Field 1)

 

so what i done is created 2 catalog script 

script 1  I want to make AddOptions VISIABLE when "Item = Hardware" and Hide all other options from the list

script 2 I want to hide the Door,cabinet,Desk and bring Visiable Memory,Drive,Motherboard when (Item) = "Computer"

 

Im using a onChange Script to do this and it's pointing at Item and in the code i have

SCRIPT 1

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

if(g_form.getValue('Item')=='Hardware'){
g_form.addOption('Selection', 'Door');
g_form.addOption('Selection', 'Cabinet');
g_form.addOption('Selection', 'Desk');

g_form.removeOption('Selection', 'memory');
g_form.removeOption('Selection', 'drive');
g_form.removeOption('Selection', 'Motherboard');

}}

 

SCRIPT 2

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

if(g_form.getValue('Item')=='Hardware'){
g_form.removeOption('Selection', 'Door');
g_form.removeOption('Selection', 'Cabinet');
g_form.removeOption('Selection', 'Desk');

g_form.addOption('Selection', 'memory');
g_form.addOption('Selection', 'drive');
g_form.addOption('Selection', 'Motherboard');

}}

 

Script 1 runs showing only the items with the addOption..

 

Script 2 does not show anything but --NONE--

 

Can someone set me straight

 

1 ACCEPTED SOLUTION

Rohit01998
Tera Guru

Hello @Walter Toney 

 

You can use only one OnChange Catalog Client Script:

 

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

if ( newValue == "Hardware" ){
g_form.addOption('Selection', 'Door');
g_form.addOption('Selection', 'Cabinet');
g_form.addOption('Selection', 'Desk');

g_form.removeOption('Selection', 'memory');
g_form.removeOption('Selection', 'drive');
g_form.removeOption('Selection', 'Motherboard');
}
else if ( newValue == "Computer" ){
g_form.addOption('Selection', 'memory');
g_form.addOption('Selection', 'drive');
g_form.addOption('Selection', 'Motherboard');

g_form.removeOption('Selection', 'Door');
g_form.removeOption('Selection', 'Cabinet');
g_form.removeOption('Selection', 'Desk');

}
}

 

Help others to find a correct solution by marking the appropriate response as correct answer and helpful.

Thanks,

View solution in original post

3 REPLIES 3

Prashant Ahire
Kilo Sage

Hi @Walter Toney ,

Please change the if(g_form.getValue('Item')=='Hardware'){ 
in script SCRIPT 2 
if(g_form.getValue('Item')=='Computer'){

Please Mark Helpful

Rohit01998
Tera Guru

Hello @Walter Toney 

 

You can use only one OnChange Catalog Client Script:

 

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

if ( newValue == "Hardware" ){
g_form.addOption('Selection', 'Door');
g_form.addOption('Selection', 'Cabinet');
g_form.addOption('Selection', 'Desk');

g_form.removeOption('Selection', 'memory');
g_form.removeOption('Selection', 'drive');
g_form.removeOption('Selection', 'Motherboard');
}
else if ( newValue == "Computer" ){
g_form.addOption('Selection', 'memory');
g_form.addOption('Selection', 'drive');
g_form.addOption('Selection', 'Motherboard');

g_form.removeOption('Selection', 'Door');
g_form.removeOption('Selection', 'Cabinet');
g_form.removeOption('Selection', 'Desk');

}
}

 

Help others to find a correct solution by marking the appropriate response as correct answer and helpful.

Thanks,

manjusha_
Kilo Sage

@Walter Toney 

 

In your both if condition ,first clear all options and then add the required options

 

if(g_form.getValue('Item')=='Hardware'){
g_form.clearOptions('Selection');
g_form.addOption('Selection', 'Door');
g_form.addOption('Selection', 'Cabinet');
g_form.addOption('Selection', 'Desk');
}}

if(g_form.getValue('Item')=='Hardware'){
g_form.clearOptions('Selection');
g_form.addOption('Selection', 'memory');
g_form.addOption('Selection', 'drive');
g_form.addOption('Selection', 'Motherboard');

}}

you can add index as well for sequencing as below
g_form.addOption('Selection', 'memory',1);//1,2,3 etc 

 

 

If my answer solved your issue, please mark my answer as Correct & 👍Helpful based on the Impact

 

Thanks,

Manjusha Bangale