Getting the value of multiple selected options
var foo = []; $('#multiple :selected').each(function(i, selected){ foo[i] = $(selected).text(); }); // to get the selected values, just use .val() - this returns a string or array foo = $('#multiple :selected').val();
We’re using jQuery’s “each()” method to loop through all selected options in a multiple select list. Each value or text value is read into an array for later use.
Most popular snippets