Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I select all options of multi-select select box on click?

This is my HTML

<select name="countries" id="countries" MULTIPLE size="8">    <option value="UK">UK</option>    <option value="US">US</option>    <option value="Canada">Canada</option>    <option value="France">France</option>    <option value="India">India</option>    <option value="China">China</option> </select> <br /> <input type="button" id="select_all" name="select_all" value="Select All"> 

When user click on 'Select All' button, I want all the options in the select box to be selected

$('#select_all').click( function() {     // ? }); 
like image 841
skos Avatar asked Mar 29 '12 11:03

skos


People also ask

How do I select all options in select?

Windows: We need to hold down the CTRL button to select multiple options. Mac: We need to hold down the command button to select multiple options.

How do I select multiple options in select tag?

Selecting multiple options vary in different operating systems and browsers: For windows: Hold down the control (ctrl) button to select multiple options. For Mac: Hold down the command button to select multiple options.


1 Answers

Try this:

$('#select_all').click(function() {     $('#countries option').prop('selected', true); }); 

And here's a live demo.

like image 87
Darin Dimitrov Avatar answered Sep 21 '22 01:09

Darin Dimitrov