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.
Use of any information from my blog posts should be at own risk and I do not hold any liability towards any information misuse or damages caused by following any of my posts.
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