Referenceselect

<select>

<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.

Attributes and Properties

Attributes for <select>
AttributeTypeValues
asList = "…""true" "false"
numToSelect = "…"integer
type = "…"
withReplacement = "…"boolean"true" "false"
Props for <select name="s">
PropertyType
$s.numToSelectinteger
$s.withReplacementboolean

Example: Default <select>

The default selection type is math. If options are simple math expressions these can be placed in a space-selected list between the opening and closing <select> tags.

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 muliple selections), then either (1) the desired child can be referenced by index or (2) the desired child can be given a name (make sure to create the same names for that particular child over the range of all possible options) and then referenced by name.

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 first index refers to the selection made from the <select> component, and the second index 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 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.