Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

validating with select 1

Status
Not open for further replies.

TheConeHead

Programmer
Joined
Aug 14, 2002
Messages
2,106
Location
US
How can I check the "text" of a select option as opposed to the value?

[conehead]
 
Code:
document.forms["formName"].elements["selectBoxName"].options[i].text

(or use innerHTML)

-kaht

[small] <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B>[/small]
[banghead] [small](He's back)[/small]
 
How would I just get the selected option?

[conehead]
 
Code:
document.forms["formName"].elements["selectBoxName"].options[[!]document.forms["formName"].elements["selectBoxName"].selectedIndex[/!]].text

-kaht

[small] <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B>[/small]
[banghead] [small](He's back)[/small]
 
Ahhh, that I could give you two stars... thanks...

[conehead]
 
np [thumbsup2]

-kaht

[small] <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B>[/small]
[banghead] [small](He's back)[/small]
 
For the sake of clarity, you could shorten kaht's idea (and the width of this thread!) to:

Code:
var dfe = document.forms["formName"].elements["selectBoxName"];
var txt = dfe.options[dfe.selectedIndex].text

...I mean... as long as your anxious to give out another star... [blush]

Dave

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...east is east and west is west and if you take cranberries and stew them like applesauce
they taste much more like prunes than rhubarb does
[infinity]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top