Possible Duplicate:
Getting the value of the selected option tag in a select box
For a SELECT box, how do I get the value and text of the selected item in jQuery?
For example,
<option value="value">text</option>
<select id="ddlViewBy">
<option value="value">text</option>
</select>
JQuery
var txt = $("#ddlViewBy option:selected").text();
var val = $("#ddlViewBy option:selected").val();
JS Fiddle DEMO
$("#yourdropdownid option:selected").text(); // selected option text
$("#yourdropdownid").val(); // selected option value
$('select').val() // Get's the value
$('select option:selected').val() ; // Get's the value
$('select').find('option:selected').val() ; // Get's the value
$('select option:selected').text() // Gets you the text of the selected option
Check FIDDLE
You can do like this, to get the currently selected value:
$('#myDropdownID').val();
& to get the currently selected text:
$('#myDropdownID:selected').text();
on the basis of your only jQuery
tag :)
HTML
<select id="my-select">
<option value="1">This is text 1</option>
<option value="2">This is text 2</option>
<option value="3">This is text 3</option>
</select>
For text --
$(document).ready(function() {
$("#my-select").change(function() {
alert($('#my-select option:selected').html());
});
});
For value --
$(document).ready(function() {
$("#my-select").change(function() {
alert($(this).val());
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With