Link to home
Start Free TrialLog in
Avatar of KS_Mis
KS_Mis

asked on

ListBox delete all selected items

Hi,

I am trying to delete all the selected items in the listbox.
I am not sure what I am doing wrong.
here is my code:

function DoRemove()
{

var sourceListBox = document.getElementById('ctl00_ContentPlaceHolder1_GetListOfLocation');
var List = sourceListBox.options.length;
 selectedIndex=null;      
 
      if (sourceListBox != null)
      {
        for (var i=0; i < List; i++)
        {
           // if (sourceListBox.options[i].selected)
           if (sourceListBox.Selected[i]) then
           
            {
               // sourceListBox.remove(sourceListBox.options.selectedIndex);
               //sourceListBox.remove(sourceListBox.options[i].selectedIndex);
               //sourceListBox.Items.Delete(i);
            }
        }
    }
}

the error says: 'options[...].selected' is null or not an object.

Thanks,
Avatar of KS_Mis
KS_Mis

ASKER

var sourceListBox = document.getElementById('ctl00_ContentPlaceHolder1_GetListOfLocation');
var List = sourceListBox.options.length;
 selectedIndex=null;      
 
      if (sourceListBox != null)
      {
        for (var i=0; i < List; i++)
        {
           if (sourceListBox.options[i].selected)
            {
               sourceListBox.remove(sourceListBox.options.selectedIndex);
            }
        }
    }
}
ASKER CERTIFIED SOLUTION
Avatar of TimCottee
TimCottee
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of KS_Mis

ASKER

Thank you