user1177860
user1177860

Reputation: 509

How to remove a list option item in a select field?

I have the following code:

function removeUsers()
        {

            var removedUsers = document.getElementById('<%=removedUsers.ClientID%>');
            var lbCurrent = document.getElementById('<%=lbCurrent.ClientID%>');

            if (lbCurrent && lbCurrent.selectedIndex != -1) 
            {
                for(i=lbCurrent.length-1; i>=0; i--)
                {
                    if(lbCurrent.options[i].selected)
                    {
                        //add the removed user to the removedUsers var
                        removedUsers.value += lbCurrent.options(i).value + ";";
                        lbCurrent.options[i] = null;
                    }
                }
            }   
            selectAllItems();       
        }

This is causing me problems in firefox:

removedUsers.value += lbCurrent.options(i).value + ";";

Can someone help??

Thanks

Upvotes: 1

Views: 94

Answers (3)

AshBrad
AshBrad

Reputation: 492

Are you a mac user? Often times firefox will suffer from javascript hang-ups that other browsers do not do to the way it processes extensions. Firefox often recommends starting in safe mode (which disables all plug-ins temporarily). It might be possible that there is a conflict with the function you are running and one of your Firefox plugins. To run Firefox in safe-mode on mac - open the browser while holding option - more info here: http://kb.mozillazine.org/Safe_Mode#Starting_Safe_Mode.

I've suffered a few javascript conflicts in my own coding.

If that doesn't solve it, could provide a few more details on what exactly is/isn't working? Also, does firebug report any javascript errors?

Thanks,

Upvotes: 0

m1.
m1.

Reputation: 1335

tried changing it to this?

   removedUsers.value += lbCurrent.options[i].value + ";";

Upvotes: 1

Dogbert
Dogbert

Reputation: 222398

removedUsers.value += lbCurrent.options(i).value + ";";

should be

removedUsers.value += lbCurrent.options[i].value + ";";

Assuming lbCurrent.options is an Array.

Upvotes: 1

Related Questions