Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
text (Option element)
all
alt
ch
dir
id
min
rel
top
url
URL
urn
Collapse the table of content
Expand the table of content

text property

Sets or retrieves the text string specified by the option tag.

Syntax

JavaScript

p = object.text

 

Property values

Type: String

the text.

Standards information

Remarks

Assigning a value to the text property changes the text property internally, but does not cause the listed value to change. Submitting the form submits the internally stored value, not the one displayed.

Examples

This example uses the text property to change the text string of each option each time the user selects an option.

Code example: http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/text_3.htm


<script type="text/javascript">
function fnShow(){
    for(var i=0;i<oSel.options.length;i++){
		oSel.options[i].text+=" (slugs)";
}
}
function fnFlash(){
    var sQuery="";
    for(var i=0;i<oSel.options.length;i++){
        sQuery+=i + " - Value=" + oSel.options[i].value + 
        " - Text=" + oSel.options[i].text + "\n";
    }
    alert(sQuery);
}
</script>
<select id="oSel" onchange="fnFlash()">
  <option value="US">Seattle</option> 
  <option value="FRANCE">Paris</option>
  <option value="MEXICO">Cabo San Lucas</option>
</select> <input onclick="fnShow()" type="button" value="Show Attractions"> 

See also

option

 

 

Show:
© 2015 Microsoft