Reputation: 949
I'm using following html for dropdownlist,
<select id="dd">
<option>Select ReportType</option>
<option value="1">Blocked Details</option>
<option value="2">Supervisor Input</option>
</select>
i want to get the option value(1/2) in a variable while changing the option. if i use the following code,
var value = $('#dd :selected').val();
i'm getting "Blocked Details/Supervisor" Input in the variable i want to get "1/2"
what is the jquery to get it?
Upvotes: 1
Views: 1795
Reputation: 20418
Try this
$('#dd').on('change', function() {
var id= this.value;
alert(id);
});
OR
var value = $('#dd').val();
var value = $('#dd :selected').val();//this also works
Upvotes: 0
Reputation: 388316
just use the select element
var value = $('#dd').val();
Demo: Fiddle
Upvotes: 2