text property
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 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
Show: