Problem with multiple select removing more than 1 option

Posted by SoLoGHoST on Stack Overflow See other posts from Stack Overflow or by SoLoGHoST
Published on 2010-06-12T04:38:30Z Indexed on 2010/06/12 4:42 UTC
Read the original article Hit count: 362

Ok, there seems to be a problem with the JS Code for Opera browsers, as it only removes the last option tag that is selected within a multiple select tag, can someone please help me.

Here is the HTML for this:

<select id="actions_list" name="layouts" multiple style="height: 128px; width: 300px;">
    <option value="forum">forum</option>
    <option value="collapse">collapse</option>
    <option value="[topic]">[topic]</option>
    <option value="[board]">[board]</option>
</select>

Ofcourse it's within a form tag, but there's a ton more code involved with this form, but here is the relevant info for this.

Here is the JS that should handle this, but only removes the last selected option in Opera, not sure about other browsers, but it really needs to remove all selected options, not just the last selected option... argg

var action_list = document.getElementById("actions_list");
var i = action_list.options.length;
while(i--)
{
    if (action_list.options[i].selected)
    {
        action_list.remove(i);
    }
}

What is wrong with this? I can't figure it out one bit :(

Thanks :)

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about select