NOTE: This article is 3 years or older so its information may no longer be relevant. Read on at your own discretion! Comments for this article have automatically been locked, refer to the FAQ
for more details.
Sometimes a need arises to get the text of the selected option
in a drop-down list
. Using some jQuery selectors
this is possible, but first lets see what doesn't work.
Lets say I have a drop-down list
defined like this:
Which looks like:
If I do a naive thing such as...
...the output is a very confusing jumble of all your option
Instead you have to use the :selected
selector on the drop-down list option
value like so...
This produces the correct output that is a single text value for the currently selection option.
A quick disclaimer...
Although I put in a great effort into researching all the topics I cover, mistakes can happen.
If you spot something out of place, please do let me know.
All content and opinions expressed on this Blog are my own and do not represent the opinions of my employer (Oracle).
Use of any information contained in this blog post/article is subject to this disclaimer
Other posts you may like...