Skip to content Skip to sidebar Skip to footer

How To Create Select All Option From Dropdown?

I am having problem in my search box, actually i have created a search box for multiple selection and it is working properly,

Solution 1:

try this

Jquery Code:

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

Live Demo :

http://jsfiddle.net/3nUPF/177/

Solution 2:

You can achieve this using jQuery :

EDIT :- You can select multiple value by pressing Ctrl button of your keyboard and you can get those value using print_r($_POST['countries']);

<selectname="countries"id="countries"MULTIPLEsize="8"><optionvalue="all">Select all</option><optionvalue="UK">UK</option><optionvalue="US">US</option><optionvalue="Canada">Canada</option><optionvalue="France">France</option><optionvalue="India">India</option><optionvalue="China">China</option></select>

jQuery :

<script>

$(document).ready(function()
{

    $('#countries').change(function() {

        if($(this).val() == 'all')
        {
            $('#countries option').prop('selected', true);
        }

    });

});

</script>

Working Demo

Post a Comment for "How To Create Select All Option From Dropdown?"