• 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
Marshal
Posts: 3704
197
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
Marshal
Posts: 3704
197
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: 65900
135
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: 65900
135
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.


 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!