Retreiving text in selectedIndex

T

tuxedo

At risk of asking a stupid question, I'd like to return the displayed
text-string of the selectedIndex contained in an options menu, and so I
tried the following one-liner:

document.forms[0].myDinner.options.selectedIndex.text;

But the above returns "undefined" for some reason? Although its not...

While if I do it in 2 steps, I can retrieve the correct string in a
roundabout way:

var where = document.forms[0].myDinner.options.selectedIndex;
alert(document.forms[0].myDinner.options[where].text)

What did I do wrong by the one-liner?

Thanks!
 
B

Bart Van der Donck

tuxedo said:
At risk of asking a stupid question, I'd like to return the displayed
text-string of the selectedIndex contained in an options menu, and so I
tried the following one-liner:

document.forms[0].myDinner.options.selectedIndex.text;

But the above returns "undefined" for some reason?

document.forms[0].myDinner.options[document.forms[0].myDinner.selectedIndex].text
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top