?
Solved

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

Posted on 2008-06-19
2
Medium Priority
?
583 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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
This article discusses how to implement server side field validation and display customized error messages to the client.
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…
Suggested Courses

800 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