Get Current Selected Option
$('#sel').
Solution 1:
$('#sel').change(function(){
alert($(this).find('option:selected').attr('id'));
});
should work.
Solution 2:
$("#sel").change(function(){
alert( this.options[this.selectedIndex].id );
})
Solution 3:
<option> tags should have a value attribute. When one is selected, you get it's value using $("#sel").val().
<select id="sel">
<optionvalue="1">aa</option><optionvalue="2">bb</option><optionvalue="3">cc</option>
</select>
$("#sel").change(function(){
alert($(this).val())
});
Solution 4:
To get the selected option inside a select element, you can use selectedIndex, then you can use the options array to get to the selected option object
$("#sel").change(function(){
alert( this.options[this.selectedIndex].id )
})
Solution 5:
Try this
$("#sel").find('option:selected').attr('id');
Ideally you should use value attribute for option tags and just use val method to get the selected value from the dropdown element. $("#sel").val();
Post a Comment for "Get Current Selected Option"