I have a selection box that allows you to select multiple options. I need to access all the selected values with JavaScript - possible a array of values?
This is the best way to get an array of the selected values back:
$("#mySelect").val(); // Return an array of the selected options values
This assumes that multiple="mutliple" and size is greater than one on the select element.
var values = [];
$('#my_select option:selected').each(function(i, selected){
values[i] = $(selected).attr('value');
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With