<option>
<option> is a General Operator
component that defines a selection element within a <select> block.
If only <math> type components are to be selected, the <option>
component can be excluded and selection items can simply be listed with a space between list items.
However, if multiple types or complex selections are required, the <option> component is necessary.
When varying component types are used as options, such as
a <text>, <function>,
or <number>, these tags are nested within the <option> tag.
Attributes and Properties
Attributes for <option>
Other (2)
textListFromString. Variant indices for which this option is selected.
number. Default value: 1. Relative weight when randomly selecting an option.
Common to all components (9)
copyreference. Create an independent copy of another component by reference. Enter a references a $name.
disabledboolean. Default value: false. Whether this component is disabled and cannot be interacted with.
extendreference. Extend another component by reference, inheriting its children and attributes. Enter a reference as $name.
fixedboolean. Default value: false. Whether this component's value is fixed and cannot be modified.
fixLocationboolean. Default value: false. Whether this component's location is fixed (preventing it from being moved while still allowing other modifications).
hideboolean. Default value: false. Whether to hide this component from the rendered output.
isResponseboolean. Default value: false. Whether this component is treated as a response for the purposes of assessment.
nametext. The name used to reference this component from elsewhere in the document.
styleNumberinteger. Default value: 1. The style number used to select this component's visual styling from the available style definitions.
Properties for <option name="o">
Other (6)
$o.disabledboolean. Whether this component is disabled and cannot be interacted with.
$o.fixedboolean. Whether this component's value is fixed and cannot be modified.
$o.fixLocationboolean. Whether this component's location is fixed (preventing it from being moved while still allowing other modifications).
$o.selectForVariantstextListFromString. Variant indices for which this option is selected.
$o.selectWeightnumber. Relative weight when randomly selecting an option.
Common to all components (4)
$o.doenetMLtext. The DoenetML source code that produced this component.
$o.hideboolean. Whether to hide this component from the rendered output.
$o.isResponseboolean. Whether this component is treated as a response for the purposes of assessment.
$o.styleNumberinteger. The style number used to select this component's visual styling from the available style definitions.
Examples
Example: <option> type math
Three options for a variable name are nested within a <select>. The
type of each <option> must be specified.
Select a new page variant from the pulldown menu at the top of the editor to see different variants of the document.
Example: <option> type text
Three options for a variable name are nested within a <select>. The
type of each <option> must be specified.
Select a new page variant from the pulldown menu at the top of the editor to see different variants of the document.
Example: <option> type vector
Three options for a variable name are nested within a <select>. The
type of each <option> must be specified.
Select a new page variant from the pulldown menu at the top of the editor to see different variants of the document.
Example: Multiple <option> types within a <select>
The <option> component is used to define multiple
component types as choices within a <select> block.
Select a new page variant from the pulldown menu at the top of the editor to see different variants of the document.
Example: Retrieving <option> selections with multiple elements
It is possible to group several components for selection within a single <option> component.
In order to reference a specific component within a selected <option>, use array notation.
The first index of the array notation refers to the selected <option> component, and the
second index refers to the specific component within the <option> component.
Select a new page variant from the pulldown menu at the top of the editor to see different variants of the document.
Attribute Examples
Attribute Example: selectWeight
The <option> component is used with the selectWeight attribute. This attribute takes any numerical value and defaults to 1. In the case below, the red option is twice as likely to be selected during recursive selections (note that the <select> component has attribute specification withReplacement="true") as the green or yellow options.
Select a new page variant from the pulldown menu at the top of the editor to see different variants of the document.
Attribute Example: selectForVariants
selectForVariants pins this <option> to specific named variants of
the document. Paired with variantNames on
<variantControl>, it lets the author control
exactly which option appears in which variant — useful when the variants
need to line up with a specific story, image, or partner answer key
rather than being randomly assigned. In the example, the apple variant
always shows red, banana always shows yellow, and cherry always
shows dark red.
A few rules to keep in mind:
- It’s all-or-nothing per
<select>: either no option usesselectForVariants, or every variant name declared by<variantControl>is covered. - Each variant name has to be listed in exactly as many options as the
<select>’snumToSelect(the default is 1). FornumToSelect="3", each variant name must appear in three options’selectForVariantslists. - Multiple variant names are space-separated, and matching is case-insensitive.
Attribute Example: selectForVariants with multiple choices per variant
When numToSelect is greater than 1, each variant name has to appear in
exactly that many options’ selectForVariants lists. Here each variant
name (apple, banana, cherry) appears in exactly two options, so the
apple variant produces red, yellow, banana produces red, dark red,
and cherry produces yellow, dark red.