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

How to take the text from a select combo box?

Status
Not open for further replies.

thelordoftherings

Programmer
May 16, 2004
616
IL
Hello,

I have an HTML Select combo box:
<select name="empID">
<option value="1>one</option>
</select>

My question is how to take the text and not the value (I want the "one" and not the value 1)
 
Hiya, i was wondering if you had the code to select the text from the combo box instead of the value.

i think i read you had found this out?

kind regards
Dave

d.hunt@executrack.com
 
It was long time ago and I don't have the code anymore but if I remember correctly try options tag of the Select element. It is an array corresponding to options in a Select object in source order.
 
You can do:

Code:
function doAlert( obj, opt ) {
    alert( obj.options[opt].innerHTML );
}

<form name="f">
<select name="s" onchange="doAlert(this, this.selectedIndex);">
  <option value="1">One</option>
  <option value="2">Two</option>
  <option value="3">Three</option>
</select>
</form>

*cLFlaVA
----------------------------
[tt]your mom goes to college[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
[banghead]
 
the "text" property of the selected option contains its text.

mySelectObj.options[mySelectObj.selectedIndex].text

-jeff
try { succeed(); } catch(E) { tryAgain(); } finally { rtfm(); }
i like your sleeves...they're real big
 
or, document.form1.selectName[document.form1.selectName.selectedIndex].text

:p
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top