Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Aug 2005
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question How can I clear a Select listbox that was populated dynamically?

    I use the following code but it didn't work:<br>
    Code:
    var selectList = document.getElementById("mylist");
    for (i=0;i<selectList.options.length;i++)
    {
         selectList.removeChild(selectList.options.item(i));	
    }
    Please help.

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,959
    Thanks
    0
    Thanked 236 Times in 233 Posts
    Simply setting the options length to zero will delete all the items.
    Code:
    selectList.options.length = 0;


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •