Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery Get Selected Option From Dropdown

Usually I use $("#id").val() to return the value of the selected option, but this time it doesn't work. The selected tag has the id aioConceptName

html code

<label>Name</label> <input type="text" name="name" /> <select id="aioConceptName">     <option>choose io</option>     <option>roma</option>     <option>totti</option> </select> 
like image 307
William Kinaan Avatar asked May 18 '12 20:05

William Kinaan


People also ask

How do I select a specific item in a Dropdownlist using jQuery?

With jQuery, it's easy to get selected text from a drop-down list. This is done using the select id. To change the selected value of a drop-down list, use the val() method.

How do you check if a dropdown is selected in jQuery?

$('#mySelectBox option'). each(function() { if ($(this). isChecked()) alert('this option is selected'); else alert('this is not'); });


1 Answers

For dropdown options you probably want something like this:

var conceptName = $('#aioConceptName').find(":selected").text(); 

The reason val() doesn't do the trick is because clicking an option doesn't change the value of the dropdown--it just adds the :selected property to the selected option which is a child of the dropdown.

like image 70
Elliot Bonneville Avatar answered Sep 26 '22 22:09

Elliot Bonneville