<select id="abc" multiple="multiple"> <option value="A">A</option> <option value="B">B</option> <option value="C">C</option> <option value="D">D</option> <option value="E">C</option> </select>
I wish to retrieve all selected values.
No matter what I try it seems to only give me the value of the selected item that is lowest in the list. So if I select A, B, and C it will only return C.
These are the things I have tried:
$('#abc').val() $('#abc').text() $('#abc :selected').val() $('#abc :selected').text() $('#abc option:selected').val() $('#abc option:selected').text()
The version of jQuery I am using is v1.9.1
Advertisement
Answer
You need to loop through all selected element within select using .each()
to get access them individually:
$('#abc :selected').each(function(){ console.log($(this).text()); });
or to get the values in array
var selectedvals = $('#abc').val();