Reputation: 169
I have some trouble with a HTML dropdown and jQuery. One option is preselected
<select id="category">
<option value="1" selected="selected">Value 1</option>
<option value="2">Value 2</option>
</select>
I try to get the selected value with this line
$("#category").val();
But I get always the preselected option "1". Also variants like
$("select option:selected").val();
don't work.
Any suggestions?
Upvotes: 0
Views: 260
Reputation: 91349
$("#category").val()
gives you the selected option value.
Upvotes: 1
Reputation: 87073
I think you need this:
$("#category option:selected").text();
Because. $('#category').val()
will output you the value
attribute of selected option.In order to get the text
of that selected option you need above.
Upvotes: 0