Language References
Indicates that this option is the default choice.
Inline |
<OPTION SELECTED ... > |
Script |
[ bSelected = ] select.options [ iIndex ] .selected |
false |
The item is not selected as the default. |
true |
The item is selected as the default. |
This property returns or accepts only a boolean value, meaning true if set, and false if not. The property is read/write with a default value of false.
If none of the options in a menu has the property set, the first item is selected by default.
The selected property is used to determine whether a value is submitted with the form. If the value of the control matches the default value, the control's value is not submitted. The value is only submitted when the control's value does not match the default value.
The following example shows how the selected property is used to retrieve the chosen options in a SELECT object whose multiple attribute is set to allow selecting multiple items in a list.
<script language="JavaScript">
<!--
function getSels ( ) {
var list =
document.forms [ 'theForm' ] .elements [ 'theSelect' ] ;
var sels="";
for ( i=0;i<list.options.length;i++ )
if ( list.options [ i ] .selected )
sels += list.options [ i ] .text+"\n";
if ( sels.length>0 )
alert ( "You have selected: \n"+sels );
else
alert ( "You have not selected anything." );
}
//-->
</script>
Show me
OPTION
defaultSelected, SELECT, multiple, selectedIndex, options