This week's giveaway is in the Spring forum.
We're giving away four 3 month subscriptions to Marco Behler Videos and have Marco Behler on-line!
See this thread for details.
Win a 3 month subscription to Marco Behler Videos this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Retrieving the text of the selected option in a select element  RSS feed

 
peter meyer
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have the following dropdown field



I need to get the option text and not the value with java script...

This is not working:


Any help is appreciated...
Thanks
 
Tim Cooke
Sheriff
Posts: 3747
208
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're going to need to expand a little on "This is not working".

However, it does work for me. It also works using .innerHTML in place of .text
 
peter meyer
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tim Cooke

I have this Java Script section in my php file...
And it will not take my text of the selected option.

How did you made you test?
If I would like to test it in a blank html file only with with my dropdown field and the java script?
Where and how do I have to set my "console.log()" to see the resulat?


Thanks a lot...
 
Tim Cooke
Sheriff
Posts: 3747
208
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tested with a very simple HTML page. I'm not a very good front end developer and I'm sure more seasoned JavaScript engineers, i.e. Bear, will scald me for using an alert() rather than console logging but it's the easiest thing I can do off the top of my head.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66057
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Life is too short not to be using jQuery for stuff like this, where the .val() method on the select element gets you the selected value.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66057
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Cooke wrote:Bear, will scald me for using an alert() rather than console logging but it's the easiest thing I can do off the top of my head.


 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!