Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

JQuery Get Selected Option From Dropdown

Normally I use $("#id").val() to return the worth of the chose alternative, however this time it doesn't work. The chose 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>
by

5 Answers

ninja01
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.
RoliMishra
Try this for value

$("select#id_of_select_element option").filter(":selected").val();


Try this one for text

$("select#id_of_select_element option").filter(":selected").text();
aashaykumar
Set the values for each of the options

<select id="aioConceptName">
<option value="0">choose io</option>
<option value="1">roma</option>
<option value="2">totti</option>
</select>

$('#aioConceptName').val() didn't work because .val() returns the value attribute. To have it work properly, the value attributes must be set on each <option>.

Now you can call $('#aioConceptName').val() instead of all this :selected voodoo being suggested by others.
kshitijrana14
try this one:
var box = document.getElementById('aioConceptName');
conceptName = box.options[box.selectedIndex].text;
sandhya6gczb
Use the following code

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

or generically

$('#id :pseudoclass')

Login / Signup to Answer the Question.