Solved

How do I delete all  <select>'s element?

Posted on 2008-06-19
2
572 Views
Last Modified: 2012-05-05
I'm trying to delete all element of <select></select>.
All element will be dynamically generated with document.createElement('option'); triggered by my php script.

It actually deletes the element(s), but not everything and not same reuslt everytime.
I just need delete all elements.
Please someone advise.
Thank you.
var delSel = document.getElementById('tlist');

  if (delSel.length > 0)

  {

	for (var i=0; i <= delSel.length; i++)

	{

		delSel.remove(delSel[i]);

	}

  }

Open in new window

0
Comment
Question by:eb110k
2 Comments
 
LVL 39

Accepted Solution

by:
Pratima Pharande earned 500 total points
ID: 21828603
var sourceListBox = document.getElementById('tlist');
var List = sourceListBox.options.length;
 selectedIndex=null;      
 
      if (sourceListBox != null)
      {
        for (var i=List-1; i >=0; i--)
        {
         
               sourceListBox.remove(sourceListBox.options[i].Index);
           
        }
    }
}
0
 

Author Closing Comment

by:eb110k
ID: 31469048
Thank you.
It worked perfectly.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now