How do you determine which option is selected in a drop-down box using jquery?
Thanks.
$('#mySelect').val();
Will give the value associated with the selected option (the value
attribute if one exists, or the text otherwise).
$('#mySelect')[0].selectedIndex;
Will give the index of the selected option.
$('#mySelect option:selected');
Will give the selected option element, from which you can grab:
$('#mySelect option:selected').text(); // the text
$('#mySelect option:selected').val(); // the value
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