Note: I have moved to wordpress. New URL is "Technology Made Easy"

Wednesday, May 16, 2007

How to remove all options from a list box using javascript?


function clearListBox(listboxID)
{
// returns 1 if all items are sucessfully removed
// otherwise returns zero.
var mylistbox = document.getElementById(listboxID);
if(mylistbox == null)
return 1;
while(mylistbox.length > 0)
{
mylistbox.remove(0);
}
return 1;
}

3 comments:

aamit said...

Hi

Can we use

mylistbox=null;

to remove all options...

MM_Farahat said...

you may use :

list.innerHTML='';

Debiprasad said...

if using jQuery, then

$('#listboxID').html('');

Ratings by outbrain