Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the selected option value in jQuery

Tags:

jquery

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);
});
like image 691
Misha Moroshko Avatar asked Apr 18 '10 15:04

Misha Moroshko


People also ask

How do I get the select box 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.

How do I get the selected value of multiple dropdowns in jQuery?

With jQuery, you can use the . val() method to get an array of the selected values on a multi-select dropdown list.


1 Answers

Yes.

alert($(this).val());

jQuery's val function will return the value of the selected option from a <select> element.

like image 166
SLaks Avatar answered Oct 21 '22 01:10

SLaks