Home > Abakada: Back to Basics > Language References > HTML Element Attributes > Abakada DHTML Properties Reference: text Property
Sets or retrieves the text string specified by the OPTION tag.
HTML |
N/A |
Script |
object.text = sTxt ] |
sTxt |
Text string of the OPTION tag. |
The property is read/write with no default value.
The text property controls what option text appears. The text and value properties are distinct from one another. Changing the text property will not alter an existing value, which is set within the OPTION tag.
In the following example, the text string specified after each OPTION is made available through the text property.
<script language="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 VALUE="FRANCE">Paris
<option VALUE="MEXICO">Cabo San Lucas
</select>
<INPUT TYPE=button VALUE="Show Attractions"
onclick="fnShow ( )">
Show me
OPTION