Hide options from Select box variable depending on the option selected from previous select box
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2024 03:38 PM
My requirement is that i have two select box variables Platform name and work request depending on the selection in variable Platform name, the options in work request should be shown or hidden.
Please advise how to achieve this via client script
Below script implemented but if i change selection multiple times its not working. Please advice where the issue.
do i need to add clear value ? If so please correct my code and help me out on this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2024 10:00 PM
Hello @Krishna Priya , yes you use clearOptions method to reset the choice list. In addition you should be using newValue in your conditional code, and also add default branch to add all options back. Assuming you have just three values in your choice list, the following code should work (Note the field names are different on my PDI)
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
g_form.clearOptions('u_work_request');
if (newValue === 'Email') {
g_form.addOption('u_work_request', 0, "data");
g_form.addOption('u_work_request', 1, "email");
} else if (newValue === 'Endpoint') {
g_form.addOption('u_work_request', 0, "data");
g_form.addOption('u_work_request', 2, "domain");
} else {
g_form.addOption('u_work_request', 0, "data");
g_form.addOption('u_work_request', 1, "email");
g_form.addOption('u_work_request', 2, "domain");
}
}
Hope this helps
--
Bala Guthy
If this answer solved your issue or just helped, please mark this as a solution or as helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2024 04:55 AM
Because the selection can be changed multiple times, it's best to clear the choices with each change, then re-build the list with the ones you want for each case, so it would look more like this - also removing the setValue line as it is not constructed correctly or doing anything:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var platform = g_form.getValue('Platform_name');
if (platform == "Email") {
g_form.clearOptions('work_request');
g_form.addOption('work_request', "Data ");
g_form.addOption('work_request', "Email");
} else if (platform == "Endpoint") {
g_form.clearOptions('work_request');
g_form.addOption('work_request', "Data");
g_form.addOption('work_request', "domain");
}
}