monda
monda

Reputation: 3915

Jquery/ javascript : Select all the selected values from drop down

Select box

<select id="update-select" multiple="multiple">
  <option value="3">Test1 </option>
  <option value="4">Test2 </option>
  <option value="5">Test3 /option>
  <option value="6">Test4</option>
  <option value="15">Test5</option>
</select>

I am selecting the options from another jquery click function based on some manipulation .

(say i have selected values 3 and 4)

later i want to see the values of selected option

i tried,

selectedVals = $("#update-select option:selected").val() ;
alert(selectedVals) // alerts 3

it shows only the first value selected.

Any suggestion?

Upvotes: 0

Views: 1316

Answers (2)

Rob Angelier
Rob Angelier

Reputation: 2333

You should use:

$("#update-select option:selected").each(function(i,elem){
   alert($(elem).val());
});

Here's an example: http://jsfiddle.net/5jNWY/

Hope this helps!

Upvotes: 0

Arun P Johny
Arun P Johny

Reputation: 388316

this should do

selectedVals = $("#update-select").val() ;

Upvotes: 3

Related Questions