addOption isn't working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2022 11:28 AM
Hi team,
Based on location, choices should appear to user. I am using client script but doesn't work as expected.
There are 4 phones (Apple, OnePlus, Oppo, Redmi).
Few countries like INDIA, Korea, Malaysia, china (8938b7111b121100763d91eebc0713ec,4d38b7111b121100763d91eebc0713eb,4938b7111b121100763d91eebc0713ed,c538b7111b121100763d91eebc0713eb,9138b7111b121100763d91eebc0713f6) should have only Redmi,
canada and United states should have all phones, and
other countries should have Apple, OnePlus, Oppo.
Please help me on this.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var loc = g_form.getValue('country');
var locationList = '8938b7111b121100763d91eebc0713ec,4d38b7111b121100763d91eebc0713eb,4938b7111b121100763d91eebc0713ed,c538b7111b121100763d91eebc0713eb,9138b7111b121100763d91eebc0713f6'; //INDIA, Korea, Malaysia, china
var locationList1 = 'dd38b7111b121100763d91eebc0713f5,1d38b7111b121100763d91eebc0713f5'; //United state and canada
if (locationList.indexOf(loc) > -1) //INDIA, Korea, Malaysia, china
{
g_form.clearOptions('phone');
g_form.addOption('phone', '4', 'Redmi');
}
if (locationList1.indexOf(loc) > -1) // United state and canada
{
g_form.clearOptions('phone');
g_form.addOption('phone', '1', 'Apple');
g_form.addOption('phone', '2', 'OnePlus');
g_form.addOption('phone', '3', 'Oppo');
g_form.addOption('phone', '4', 'Redmi');
} else { //rest other country
g_form.clearOptions('phone');
g_form.addOption('phone', '1', 'Apple');
g_form.addOption('phone', '2', 'OnePlus');
g_form.addOption('phone', '3', 'Oppo');
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2022 12:08 PM
Hi Priyanka,
Try using the following script.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var loc = g_form.getValue('country');
var locationList = '8938b7111b121100763d91eebc0713ec,4d38b7111b121100763d91eebc0713eb,4938b7111b121100763d91eebc0713ed,c538b7111b121100763d91eebc0713eb,9138b7111b121100763d91eebc0713f6'; //INDIA, Korea, Malaysia, china
var locationList1 = 'dd38b7111b121100763d91eebc0713f5,1d38b7111b121100763d91eebc0713f5'; //United state and canada
g_form.clearOptions('phone');
if (locationList.indexOf(loc) > -1) //INDIA, Korea, Malaysia, china
{
g_form.addOption('phone', '4', 'Redmi');
}
else if (locationList1.indexOf(loc) > -1) // United state and canada
{
g_form.addOption('phone', '1', 'Apple');
g_form.addOption('phone', '2', 'OnePlus');
g_form.addOption('phone', '3', 'Oppo');
g_form.addOption('phone', '4', 'Redmi');
} else { //rest other country
g_form.addOption('phone', '1', 'Apple');
g_form.addOption('phone', '2', 'OnePlus');
g_form.addOption('phone', '3', 'Oppo');
}
}
Hopefully, this will work now.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2022 12:14 PM
Tried to remove some redundant statements.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var loc = g_form.getValue('country');
var locationList = '8938b7111b121100763d91eebc0713ec,4d38b7111b121100763d91eebc0713eb,4938b7111b121100763d91eebc0713ed,c538b7111b121100763d91eebc0713eb,9138b7111b121100763d91eebc0713f6'; //INDIA, Korea, Malaysia, china
var locationList1 = 'dd38b7111b121100763d91eebc0713f5,1d38b7111b121100763d91eebc0713f5'; //United state and canada
g_form.clearOptions('phone');
if (locationList.indexOf(loc) > -1) //INDIA, Korea, Malaysia, china
{
g_form.addOption('phone', '4', 'Redmi');
}
else {
g_form.addOption('phone', '1', 'Apple');
g_form.addOption('phone', '2', 'OnePlus');
g_form.addOption('phone', '3', 'Oppo');
if (locationList1.indexOf(loc) > -1) // United state and canada)
g_form.addOption('phone', '4', 'Redmi');
}
}