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.
Hope you found this post useful...
...so please read on! I love writing articles that provide beneficial information,
tips and examples to my readers. All information on my blog is provided free of
charge and I encourage you to share it as you wish. There is a small favour I ask in return however -
engage in comments below, provide feedback, and if you see mistakes let me know.
If you want to show additional support and help me pay for web hosting and
domain name registration,
donations, no matter how small, are always welcome!
Use of any information contained in this blog post/article is subject to this disclaimer
Other posts you may like...