You are here: Home » JavaScript » Select all from list box

Select all from list box

78 Flares 78 Flares ×
To select all value for list box, here, i am creating a function listbox_selectall();
 and passing two parameter in this function.
Passing id of list box and true or false, 
true is using for select all and false for select none.

Always use javascript:void(0), in place of # for link, when we use #, 
page will toggle, to avoid page toggle use javascript:void(0).
<html xmlns="">
<script src="" type="text/javascript"></script>
<script type="text/javascript">
    function listbox_selectall(listID, isSelect) {
        var listbox = document.getElementById(listID);
        for(var count=0; count < listbox.options.length; count++) {
            listbox.options[count].selected = isSelect;
     <select id="country" size="5" multiple>
	<option value="1">Afghanistan</option>
	<option value="2">Bahamas</option>
	<option value="3">Barbados</option>
	<option value="4">Belgium</option>
	<option value="5">Bhutan</option>
	<option value="6">China</option>
	<option value="7">Croatia</option>
	<option value="8">Denmark</option>
	<option value="9">France</option>
    <option value="10">India</option>
    <option value="11">UAE</option>
     <option value="12">USA</option>

<a href="javascript:void(0)" onclick="listbox_selectall('country', true)">Select All Country </a>,
<a href="javascript:void(0)" onclick="listbox_selectall('country', false)">Select None Country</a>

About Abhishek Sinha

I am Abhishek and I love to code on PHP.

Leave a Reply

Your email address will not be published. Required fields are marked *


Scroll To Top
78 Flares Twitter 1 Facebook 1 Google+ 74 StumbleUpon 1 Pin It Share 0 LinkedIn 1 78 Flares ×