Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get selected value of a dropdown's item using jQuery

Tags:

jquery

How can I get the selected value of a dropdown box using jQuery?
I tried using

var value = $('#dropDownId').val(); 

and

var value = $('select#dropDownId option:selected').val(); 

but both return an empty string.

like image 336
shyam Avatar asked May 06 '10 11:05

shyam


People also ask

How can I get the selected value of a drop down list with jQuery?

Use the jQuery: selected selector in combination with val () method to find the selected option value in a drop-down list.

How do I get the text value of a selected option jQuery?

We can select text or we can also find the position of a text in a drop down list using option:selected attribute or by using val() method in jQuery. By using val() method : The val() method is an inbuilt method in jQuery which is used to return or set the value of attributes for the selected elements.

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

For single select dom elements, to get the currently selected value:

$('#dropDownId').val(); 

To get the currently selected text:

$('#dropDownId :selected').text(); 
like image 113
Peter McG Avatar answered Sep 28 '22 09:09

Peter McG