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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

select options 2

Status
Not open for further replies.

okiiyama

IS-IT--Management
Jan 3, 2003
269
US
Is it possible to get an option's text and value?
How can the following non-working example work?
Goal: alert with the option's value and text
Code:
<select name="test" onclick="alert(this.value+', '+this.text);">
<option value="1">One
<option value="2">Two
</select>

Thanks
 
Try this, though I haven't tested it.
Code:
<select name="test" onclick="alert(this[this.selectedIndex].value+', '+this[selectedIndex].text);">

Lee
 
lee,

i think (although i'm too lazy to test) that you need to reference the options collection?

Code:
<select name="test" onclick="alert(this[red].options[/red][this.selectedIndex].value+', '+this[red].options[/red][[red]this.[/red]selectedIndex].text);">



*cLFlaVA
----------------------------
[tt]"quote goes here"[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Yeah, Cory, I'd have found that out if I'd bothered to test it. :)#

Lee
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top