简体   繁体   中英

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,

<input type="text" name="search" size=15 maxlength=15 placeholder = "Gene Symbol"/>
        <select name="table[]" size = "0" multiple>
            <option selected="selected"></option>
            <option value="infla_info">Inflammation</option>
            <option value="diet_info">diet</option>
            <option value="obesity_info">obesity</option>
            <option value="stress_info">stress</option>
            <option value="athero_info">atherosclerosis</option>
            <option value="retino_info">Diabetic Retinopathy</option>
            <option value="nephro_info">Diabetic Nephropathy</option>
            <option value="neuro_info">Diabetic Neuropathy</option>
        </select>

        <input type="Submit" name="Submit" value="Gene Search"/>

after this i want to add one more option select all, by which it should show all the records or tables containing query gene.

please help me

try this

Jquery Code:

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

Live Demo :

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

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']);

<select name="countries" id="countries" MULTIPLE size="8">
   <option value="all">Select all</option>
   <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>

jQuery :

<script>

$(document).ready(function()
{

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

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

    });

});

</script>

Working Demo

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM