asp.net.ph

Skip Navigation Links

OPTION Element | OPTION Object

Language References


Denotes one choice in a selectable list.

HTML Syntax

Remarks

The OPTION element is used to define a selectable item in a selection list created with the SELECT element. OPTION can only be used within SELECT tags.

When a FORM containing a selection list is submitted for processing, the control name is provided by the SELECT element and the value provided by the selected OPTION element. If the OPTION specifies a value attribute, that value is sent. Otherwise, it is the text that follows the <option> tag. Only the selected option value ( s ) are submitted to the server.

This element is a block element.

Members

OPTION Members

Example

The following HTML creates a drop-down list box.

<form name="theForm">
<select name="theList">
   <option>Alpha Romeo
   <option>BMW
   <option>Ferrari
   <option>Mercedes-Benz
   <option>Porsche
   <option>Range Rover
</select>
</form>

Notes on DOM Access

OPTION elements can be accessed in client-side script by using the options collection of the SELECT element. The following script example retrieves and displays the text for all options in the SELECT example above.

<script language="JavaScript">
<!--
function getOpts ( ) {
var list = 
  document.forms['theForm'].elements['theList'];
var opts="";
for ( i=0;i<list.options.length;i++ )
  opts += list.options[i].text+"\n";
alert ( "These are your options: \n"+opts );}
//-->
</script>

 Show me 

Except for background-color and color, style settings applied through the style object for the OPTION object are ignored. In addition, style settings applied directly to individual options override those applied to the containing SELECT object as a whole.

See Also

selected, 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