Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get values from multiple selections in SELECT

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?

like image 531
janhartmann Avatar asked Jul 27 '26 17:07

janhartmann


2 Answers

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.

like image 76
Doug Neiner Avatar answered Jul 30 '26 07:07

Doug Neiner


var values = [];
$('#my_select option:selected').each(function(i, selected){
    values[i] = $(selected).attr('value');
});
like image 27
Soufiane Hassou Avatar answered Jul 30 '26 05:07

Soufiane Hassou