Looping through selected values in multiple select combobox JQuery

Posted by Roland on Stack Overflow See other posts from Stack Overflow or by Roland
Published on 2010-04-22T13:21:00Z Indexed on 2010/04/22 13:23 UTC
Read the original article Hit count: 229

Filed under:

I have the following scenario.

I have a combobox where multiple selection is available.

                <select id="a" multiple="multiple">
                    <option value="">aaaa</option>
                    <option value="">bbbb</option>
                    <option value="">cccc</option>
                    <option value="">dddd</option>
                </select>

Now I also have a button

<button type="button" id="display">Display</button>

When a user clicks on this button, it should list all the selected values of the dropdown in an alert box

My JS code looks as follows

  $(document).ready(function() {
                $('#display').click(function(){
                    alert($('#a').val());
                });


        });

Any pointers will be appreciated

© Stack Overflow or respective owner

Related posts about jQuery