Solved

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

Posted on 2008-06-19
2
578 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
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…

737 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