apex:selectOption

A possible value for an <apex:selectCheckboxes>, <apex:selectRadio>, or <apex:selectList> component. The <apex:selectOption> component must be a child of one of those components.

Use this component to get user input for a controller method that does not correspond to a field on an sObject. Only <apex:inputField> and <apex:outputField> can be used with sObject fields.

This component supports HTML pass-through attributes using the “html-” prefix. Pass-through attributes are attached to the generated <input> tag for components within an <apex:selectCheckboxes> or <apex:selectRadio> parent component, or to the generated <option> tag for components within an <apex:selectList> parent component.

Example 

1<!-- Page: -->
2<apex:page controller="chooseColor">
3    <apex:form>
4        <apex:selectList id="chooseColor" value="{!string}" size="1">
5            <apex:selectOption itemValue="red" itemLabel="Red"/>
6            <apex:selectOption itemValue="white" itemLabel="White"/>
7            <apex:selectOption itemValue="blue" itemLabel="Blue"/>
8        </apex:selectList> 
9    </apex:form>
10</apex:page>
11 			
12 /*** Controller ***/
13 			
14public class chooseColor {
15    String s = 'blue';
16 
17    public String getString() {
18        return s;
19    }
20 			
21    public void setString(String s) {
22        this.s = s;
23    }
24}

The example above renders the following HTML:

1<select id="chooseColor" name="chooseColor" size="1">
2    <option value="red">Red</option>
3    <option value="white">White</option>
4    <option value="blue" selected="selected">Blue</option>
5</select>

Attributes 

Attribute NameAttribute TypeDescriptionRequired?API VersionAccess
dirStringThe direction in which the generated HTML component should be read. Possible values include “RTL” (right to left) or “LTR” (left to right). 10.0global
idStringAn identifier that allows the selectOption component to be referenced by other components in the page. 10.0global
itemDescriptionStringA description of the selectOption component, for use in development tools. 10.0global
itemDisabledBooleanA Boolean value that specifies whether the selectOption component should be displayed in a disabled state. If set to true, the option appears disabled. If not specified, this value defaults to false. 10.0global
itemEscapedBooleanA Boolean value that specifies whether sensitive HTML and XML characters should be escaped in the HTML output generated by this component. If not specified, this value defaults to true. For example, the only way to add a ”>” symbol to a label is by using the symbol’s escape sequence and setting itemEscaped=“false”. If you do not specify itemEscaped=“false”, the character escape sequence displays as written. 10.0global
itemLabelStringThe label used to display this option to users. 10.0global
itemValueObjectThe value sent to the server if this option is selected by the user. 10.0global
langStringThe base language for the generated HTML output, for example, “en” or “en-US”. For more information on this attribute, see the W3C specifications. 10.0global
onclickStringThe JavaScript invoked if the onclick event occurs–that is, if the user clicks the selectOption component. 10.0global
ondblclickStringThe JavaScript invoked if the onclick event occurs–that is, if the user clicks the selectOption component twice. 10.0global
onkeydownStringThe JavaScript invoked if the onkeydown event occurs–that is, if the user presses a keyboard key. 10.0global
onkeypressStringThe JavaScript invoked if the onkeypress event occurs–that is, if the user presses or holds down a keyboard key. 10.0global
onkeyupStringThe JavaScript invoked if the onkeyup event occurs–that is, if the user releases a keyboard key. 10.0global
onmousedownStringThe JavaScript invoked if the onmousedown event occurs–that is, if the user clicks a mouse button. 10.0global
onmousemoveStringThe JavaScript invoked if the onmousemove event occurs–that is, if the user moves the mouse pointer. 10.0global
onmouseoutStringThe JavaScript invoked if the onmouseout event occurs–that is, if the user moves the mouse pointer away from the selectOption. 10.0global
onmouseoverStringThe JavaScript invoked if the onmouseover event occurs–that is, if the user moves the mouse pointer over the selectOption. 10.0global
onmouseupStringThe JavaScript invoked if the onmouseup event occurs–that is, if the user releases the mouse button. 10.0global
renderedBooleanA Boolean value that specifies whether the component is rendered on the page. If not specified, this value defaults to true. 10.0global
styleStringThis attribute was deprecated in Salesforce API version 17.0 and has no effect on the page. 10.0global
styleClassStringThis attribute was deprecated in Salesforce API version 17.0 and has no effect on the page. 10.0global
titleStringThe text to display as a tooltip when the user’s mouse pointer hovers over this component. 10.0global
valueObjectA merge field that references the controller class variable of type SelectOption that is associated with this selectOption component. For example, if the name of the associated variable in the controller class is myOption, use value=”{!myOption}” to reference the variable. 10.0global

See Also