option

< html‎ | elements
Jump to: navigation, search

option



Summary

Denotes one choice in a select element.


Overview Table

DOM Interface HTMLOptionElement

Examples

This example uses the OPTION element to create individual items in a drop-down list box.

<SELECT ID="oCars" SIZE="1" onchange="fnChange()">
<OPTION VALUE="1">BMW
<OPTION VALUE="2">PORSCHE
<OPTION VALUE="3" SELECTED>MERCEDES
</SELECT>
<TEXTAREA ID="oData"></TEXTAREA>

This example uses the options collection to append the selected item of the list box in a text area.

<SCRIPT LANGUAGE="JScript">
function fnChange(){
   oData.value+=oCars.options[oCars.selectedIndex].text + "\n";
}
</SCRIPT>

Notes

Remarks

As of Microsoft Internet Explorer 5 and later, the OPTION elements are part of the all collection. For earlier versions, you can gain access to these elements by applying the options collection to the SELECT element. You can create new OPTION elements dynamically with the document.createElement method, but you cannot change properties until the new element is added to a SELECT object. Or, you can create fully formed elements by using the Option object, as follows:

 var opt = new Option( 'Text', 'Value', fDefaultSelected ); 

You can add OPTION elements only to a SELECT element that is located in the same window where the OPTION elements are created. Except for background-color and color, style settings applied through the style object for the option element are ignored. In addition, style settings applied directly to individual options override those applied to the containing SELECT element as a whole.

Standards information


HTML information

{

Compatibility

Desktop

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support ? ? ? ? ?

Mobile

Feature Android BlackBerry Chrome for mobile Firefox Mobile (Gecko) IE Mobile Opera Mobile Opera Mini Safari Mobile
Basic support ? ? ? ? ? ? ? ?


Compatibility notes

Browser Version Note
WebKit, Blink No support for event handlers.

See also

Related pages (MSDN)

Attribution

This article contains content originally from external sources.

Portions of this content come from the Microsoft Developer Network: [Windows Internet Explorer API reference Article]