Solved

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

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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

705 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