Wednesday, October 2, 2019

javascript - 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








Answer



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.


No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...