By 05/02/2014 19 Comments

How to Select or Deselect All from Listbox in Javascript

Select or deselect all items in a listbox

  • All items at once can be selected and deselected in a listbox

The following code describes, how can you select or deselect all items in a listbox in javascript


function listboxSelectUnselect(listID, isSelect) { // pass 2 parameters first listbox, second boolean value true or false

 var listbox = document.getElementById(listID); // get listbox by id

 for(var count=0; count < listbox.options.length; count++) { // loop through each listbox value

 listbox.options[count].selected = isSelect; // set true, false or empty


<select multiple="multiple" id = "listID"> <!--- render listbox object --->
 <option value = "java">Java</option>
 <option value = "php">Php</option>
 <option value = "asp"></option>
 <option value = "boot">Bootstraps</option>
 <option value = "r">Ruby</option>
 <option value = "f">Facebook</option>
 <option value = "g">Google</option>
 <option value = "c">Css</option>

 <!--- following buttons calls above function -->
 <button onclick="listboxSelectUnselect('listID', 'true')">Select all</button>
 <button onclick="listboxSelectUnselect('listID', '')">Deselect</button>

Posted in: JavaScript

Leave your valuable Comment

Have a natural attraction for women cosmetics and replica watches uk clothes, no
more than two for men the most attractive one, is to make their own driving experience, happy and can serve as the facade of the car, another is to highlight the taste edify sentiment rolex replica watch. The replica rolex is undoubtedly the most fashionable accessories, wear a suit to attend the activities, but also get a decent match on the replica watches .