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

Select element - getting value from screen

Status
Not open for further replies.

sodakotahusker

Programmer
Mar 15, 2001
601
If on a select element I reference .value (document.all.selState.value) - I get the underlying value, in this case a numeric id for the state). How do I reference the text I see on the screen (.text does not work)?
 
I think I understand whar you're saying. If so, this is what I normally do:

Code:
var selected = document.formname.formitem.selectedIndex;
var selectedText = document.formname.formitem.options[selected].value;

(the above code is only 2 lines, and may have wrapped)
 
No - you should return the same value with one statement
document.formname.formitem.value. The browser already knows the index of the selected item.

What I want is to get the test which shows up on the screen which is not the same as the value if the value is specified in the option <option value="1">South Dakota</option><option value="2">North Dakota</option> etc.

I want to retrieve the South Dakota not the 1 or North Dakota and not the 2.
 
have you tried:

var selected = document.formname.formitem.selectedIndex;
var selectedText = document.formname.formitem.options[selected].innerHTML;


???
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top