Reputation: 196539
I have a listbox, and I want to read all of the items in a listbox using jquery. I also would like to be able to identify for each item if it is selected or not. What is the simplest way of doing this?
Upvotes: 2
Views: 9140
Reputation: 50185
Without any other information on how you want the output formatted:
$('#selectId').find('option').map(function() {
return $(this).val() + ':' + $(this).is(':selected');
});
Upvotes: 1
Reputation: 5720
$('.myListBox option').each(function(index) {
if ( ($(this).is(':selected')) {
// do stuff if selected
}
else {
// this one isn't selected, do other stuff
}
});
Upvotes: 7