n00b n00b - 2 years ago 118
HTML Question

jQuery get selected option value (not the text, but the attribute 'value')

Okay, I have this code:

<select name="selector" id="selector">
<option value="1">Option 1</option>
<option value="2">Option 2</option>

And I'd like to get the value of the option selected.
'Option 2' is selected, and the value of it is '2'. The '2' is the value I need to get and not 'Option 2'.

Answer Source

Use .val to get the value of the selected option. See below,

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download