Skip to Content
Referenceselect

<select>

Randomly selects components from a list of children to create document variants

<select> is a General Operator component that selects values from a list or from a group of nested <option> components at random. Selections generate variants of the document.

For fine-grained control over which option appears in which named variant of the document, see the selectForVariants attribute on <option> — it lets you pin specific options to specific variants instead of relying on random selection.

Attributes and Properties

Attributes for <select>

Other (4)
asList

boolean. Default value: true. Whether to render the items separated by commas (true) or with no separator (false).

integer. Default value: 1. How many child components to select.

text. Component type to select from.

boolean. Default value: false. Whether the same child can be selected more than once.

Common to all components (10)
copy

reference. Create an independent copy of another component by reference, as if its DoenetML were written here: it starts fresh, without the reader's changes, and makes its own random choices. Enter a reference as $name.

copyWithStateIn development

reference. Create an independent copy of another component by reference that starts with that component's current state, including the reader's changes and its random choices. Enter a reference as $name.

disabled

boolean. Default value: false. Whether this component is disabled and cannot be interacted with.

extend

reference. Extend another component by reference, inheriting its children and attributes. Enter a reference as $name.

fixed

boolean. Default value: false. Whether this component's value is fixed and cannot be modified.

fixLocation

boolean. Default value: false. Whether this component's location is fixed (preventing it from being moved while still allowing other modifications).

hide

boolean. Default value: false. Whether to hide this component from the rendered output.

isResponse

boolean. Default value: false. Whether this component is treated as a response for the purposes of assessment.

name

text. The name used to reference this component from elsewhere in the document.

styleNumber

integer. Default value: 1. The style number used to select this component's visual styling from the available style definitions.

Properties for <select name="s">

Other (2)
$s.numToSelect

integer. How many were selected: the number to select when the selection was made.

$s.withReplacement

boolean. Whether the same child can be selected more than once.

Common to all components (4)
$s.doenetML

text. The DoenetML source code that produced this component.

$s.hide

boolean. Whether to hide this component from the rendered output.

$s.isResponse

boolean. Whether this component is treated as a response for the purposes of assessment.

$s.styleNumber

integer. The style number used to select this component's visual styling from the available style definitions.

Examples

Example: Default <select>

The default selection type is math. If options are simple math expressions these can be written as a list between the opening and closing <select> tags, separated by commas (x + 1, y) or by spaces (x y z).

Select a new page variant from the pulldown menu at the top of the editor to see different variants of the document.


Example: <select> from a set of texts

A text is selected from a group of options.

Select a new page variant from the pulldown menu at the top of the editor to see different variants of the document.


Example: <select> components of multiple types

Multiple component types can be selected together within a single option, as a group. In order to reference a child of an <option> that has been selected, first use the index of the selection desired (in the case of multiple selections), then the name of the child. Give that child the same name in every option, so that the name refers to it whichever option is selected.

An index selects among the selections, not among the children of an option: $groupSelect[2][2] does not mean the second child of the second selection. It names nothing, and DoenetML gives a warning that shows the name to use instead. (Earlier versions read it as that child.) A selection whose whole content is one component stands for it, and passes a further index on to it: with <option><math>(1,2,3)</math></option>, $s[1][2] is 2.

Select a new page variant from the pulldown menu at the top of the editor to see different variants of the document.


Example: <select> paired values

In this example, two pairs of values are assigned to each <option> within the <select> component. In the references shown in this example, the index refers to the selection made from the <select> component, and the name after it refers to the child component within the <option> that was selected.

Select a new page variant from the pulldown menu at the top of the editor to see different variants of the document.


Example: <select> random functions for graphing

In this example, two <function>s are randomly selected from a list of <option> components nested within a <select>. The final functions are further varied by specifying coefficients and constants that have been generated using a <selectFromSequence/> component. Note that the selected coefficients have been renamed as numbers for simplicity when writing the function formulas.

Select a new page variant from the pulldown menu at the top of the editor to see different variants of the document.


Example: Assigning names to selected values

The <select> component is used to randomly select three <math> values using the numToSelect attribute.

As an author, it can sometimes become tedius to refer to indexed values (such as s[2]) every time you want to reference a selected value in subsequent code. If this is the case, descriptive names can be assigned to each selection by defining unique components which reference individual selected values.

Different page variants (which can be accessed from the left-side menu) will have different selected <math> values.

Attribute Examples

Attribute Example: numToSelect

The numToSelect attribute sets how many values are chosen from the options. The default value is 1. When more than one is selected, the individual selections are accessed by index (for example, $s[1]). Without withReplacement, each option can be chosen at most once.

numToSelect, like every attribute that decides what a random choice chooses from, may reference another random choice, such as numToSelect="$n" with <selectFromSequence name="n" from="2" to="4"/>, or content that can’t change, but not an input, a sampler such as <sampleRandomNumbers>, or anything else a reader can change. What a choice chooses from comes from what the author wrote, so such a reference is an error when the document loads, in every variant.

Select a new page variant from the pulldown menu at the top of the editor to see different variants of the document.


Attribute Example: withReplacement

Use the withReplacement attribute if the options listed may be selected more than once.


Attribute Example: type

The type attribute alerts Doenet to the type of component to select. The default type is math; therefore, text will render as math unless otherwise specified.

Last updated on