Okay, I have this code:
<select name="selector" id="selector">
<option value="1">Option 1</option>
<option value="2">Option 2</option>
</select>
And I'd like to get the value of the option selected. Example: 'Option 2' is selected, and the value of it is '2'. The '2' is the value I need to get and not 'Option 2'.
you can use
jquery
as followsSCRIPT
FIDDLE is here
Use .val to get the value of the selected option. See below,
For a select like this
... you can get the id this way:
Or you can use value instead, and get it the easy way...
like this:
jsFiddle example
.val()
will get the value.I just wanted to share my experience and my reputation is not enough to comment.
For me,
$('#selectorId').val()
returned null.
I had to use
$('#selectorId option:selected').val()