patternjavascriptCritical
jQuery Get Selected Option From Dropdown
Viewed 0 times
fromjqueryoptionselectedgetdropdown
Problem
Usually I use
The selected tag has the id
html code
$("#id").val() to return the value of the selected option, but this time it doesn't work.The selected tag has the id
aioConceptNamehtml code
Name
AIO Concept Name
choose io
roma
totti
Solution
For dropdown options you probably want something like this:
For selected text
For selected value
The reason
For selected text
var conceptName = $('#aioConceptName').find(":selected").text();For selected value
var conceptName = $('#aioConceptName').find(":selected").val();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.Code Snippets
var conceptName = $('#aioConceptName').find(":selected").text();var conceptName = $('#aioConceptName').find(":selected").val();Context
Stack Overflow Q#10659097, score: 2366
Revisions (0)
No revisions yet.