I’ve got a mtuli-select box called AgentIDList2. When I select a bunch of the options and hit a delete button I wish those options to be totally removed from AgentIDList2. Instead what’s happening, is the index is shifting everytime I delete an element so my code doesn’t work. Any ideas on how to get around this:
function remove_agents() {
var List = $('#AgentIDList2');
List = List[0];
selected = new Array();
for (var i = 0; i < List.options.length; i++) {
if (List.options[i].selected) {
selected.push(i);
}
}
// Break it out like this so we don't screw up the indices and pick the wrong item
for (i=0; i<selected.length; i++) {
List.options.remove(selected[i]);
}
}
Any ideas? Thanks!
Try this instead
Here’s a working example.