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
You have to find all the selected options:
The manual, as Pim pointed out, is useful:
So, the above should work, but jQuery already does this behind the scenes for you, so this is much easier:
If it’s not working for you, it might be because of the fact that your options don’t seem to have a value.