DelphiFAQ Home Search:
General :: Programming :: JavaScript
Code snippets to add functionality to your HTML pages, preferably cross-browser.

Articles:

This list is sorted by recent document popularity (not total page views).
New documents will first appear at the bottom.

Featured Article

Javascript to clear a listbox

Question:

How can I clear a listbox using Javascript?

Answer:

Use the code below. Call it by passing the listbox object to function clearlistbox()

function clearlistbox(lb){
   for (var i=lb.options.length-1; i>=0; i--){
     lb.options[i] = null;
   }
   lb.selectedIndex = -1;
 }
 
 
 // call it like this
clearlistbox(listbox1);
 

Generated 20:01:55 on May 26, 2017