Solved

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

Posted on 2008-06-19
2
573 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (http://www.experts-exchange.com/A_3488.html), typical array handling might look like this: (CODE) B…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

910 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

23 Experts available now in Live!

Get 1:1 Help Now