all
alt
ch
dir
id
min
rel
top
url
URL
urn
Expand Minimize

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.


<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";
    }
    console.log(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:
© 2014 Microsoft