0

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?

1

2 Answers 2

3

this should do

selectedVals = $("#update-select").val() ;
Sign up to request clarification or add additional context in comments.

Comments

0

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!

2 Comments

i want values not text
A similar solution, but with pushing the values onto an array, which is probably what you're after: jsfiddle.net/eN32E

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.