asp.net.ph

Skip Navigation Links

SELECTED Attribute | selected Property

Language References


Indicates that this option is the default choice.

Syntax


Inline <OPTION SELECTED ... >
Script [ bSelected = ] select.options [ iIndex ] .selected

Possible Values


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.

Remarks

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.

Example

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 

Applies To

OPTION

See Also

defaultSelected, SELECT, multiple, selectedIndex, options



© 2025 Reynald Nuñez and asp.net.ph. All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note