text property
[This documentation is preliminary and is subject to change.]
Sets or retrieves the text string specified by the option tag.
Syntax
| JavaScript | |
|---|
Property values
Type: String
the text.
Standards information
- Document Object Model (DOM) Level 1 Specification, Section 2.5.5
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>
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 VALUE="FRANCE">Paris
<OPTION VALUE="MEXICO">Cabo San Lucas
</SELECT>
<INPUT TYPE=button VALUE="Show Attractions" onclick="fnShow()">
Build date: 3/8/2012