I would like to print the selected values of all selects using jQuery. I did it like this, but I feel that there is a nicer way to write the same. Am I right ?
$("select").each(function() {
alert(this.options[this.selectedIndex].value);
});
Answer: Use the jQuery :selected Selector You can use the jQuery :selected selector in combination with the val() method to find the selected option value in a select box or dropdown list.
With jQuery, you can use the . val() method to get an array of the selected values on a multi-select dropdown list.
Yes.
alert($(this).val());
jQuery's val
function will return the value of the selected option from a <select>
element.
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