- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2015 03:01 AM
Hi All
I have a requirement to clear all the options selected in the right slush busket from a list collector when a variable say ' Customer' is changed instead of moving them to the left side because there is already an onchange script for the filter for every change of customer a set of new values get populated in the list collector. So when I change the customer the selected values in the list collector should disappear and show none .
Immediate help is appreciated.
this is for one customer when I change the customer it should be as shown below
Thanks
Zabee.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2015 05:17 AM
Try this:
OnChange of customer:
var varName = 'Name of your list collector';
var rightBucket = gel(varName + '_select_1');
var selectedOptions = rightBucket.options;
for(var i = 0; i < selectedOptions.length; i++){
//Check for the item to add here based on sys_id
var value = selectedOptions[i].value;
rightBucket.remove(value);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2017 07:57 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2017 06:56 PM
Sowmya,
I'm not sure if you have changed any code since your last post but the two snippets each have half the answer (at least given what works for me) - can you confirm that now when you have added 5 things all 5 are being removed ?
One uses an decreasing "for" counter (nice way to get around the changing length) but uses "rightBucket.remove(selectedOptions[i]);" to make the removal. The other uses the increasing counter (so suffers from early termination) and uses "rightBucket.remove(selectedOptions[i].value);" (if you push the two lines together).
Suggest you use the .value version of the remove in a loop that works properly (either decreasing or increasing to a static variable, not the option list length as that changes on each iteration).
Rob.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2022 03:40 AM
Hey Mujtaba,
if I remove any of the type in the list collector show a popup message and include removed value name like wm_work is removed from the list collector
how can i configure this in client script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2017 06:08 AM
I just had this exact situation and thank you for the code but I had to adjust a little more. If I had selected one item then it was successfully removed but in my next test I selected 3 and only 2 were removed. I put some alerts in and watched the selectedOptions.length report as 3 and then the loop only execute twice.
I believe the issue is that as the rightBucket.remove is executed the next loop test is against the new length not the length when you set off. So, edit #1 is to save the length in an new variable and use that for the loop condition. Having done that I got 3 passes but still an option left - it stands to reason that if the list is updating (the reason the loop was being cut short) then by the third time through selectedOptions[2] no longer exists. So I selected to remove selectedOptions[0] on every pass and this seems to do the trick...
var loop_end = selectedOptions.length;
for(var i = 0; i < loop_end; i++){
var value = selectedOptions[0].value;
rightBucket.remove(value);
}
Disclaimer: I'm a code recycler with a good sense of logic I have no in-depth knowledge of javascript - the explanation above is based on a good guess at what is going on having found code that works.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2018 11:33 AM
You are correct. The length is dynamically changing as we remove values. I solve this by starting at the end of the list and working towards the start.
- Get the length and put it into a variable.
- We have to set i to be the length minus 1 since we are working backwards; while there are 5 elements in the list, they are indexed 0 - 4, so we can't start at 5.
- We have to account for option indexed at 0, thus we do i > -1.
var rightBucket = gel(collectorName + '_select_1');
var selectedOptions = rightBucket.options;
rightLength = selectedOptions.length;
for(var i = rightLength-1; i > -1; i--){
var value = selectedOptions[i].value;
rightBucket.remove(value);
}