Choice questions in scripting
Use scripting to get and set values for Choice questions.
The functions in this topic apply to the following question types:
- Single Choice
- Multiple Choice
Note:
- All items in the data points (that is, all the answer options) are listed in authored order.
- Selection does not consider mutually exclusive answer options for Multiple Choice questions. When you select a mutually exclusive option, it doesn't unselect other choices.
Function | Description |
---|---|
question.getSelectedIndex();
|
Applies to Single Choice questions. Returns the zero-based index of the selected choice. Returns 0 if an item is selected. Returns -1 if no item is selected. |
question.getSelectedIndexes();
|
Applies to Multiple Choice questions. Returns a list of selected indices. Returns an empty array if no item is selected. |
question.set([index,…]);
|
Applies to Multiple Choice questions. Zero-based, so if you select the first two choices, the array is 0 and 1. Does not clear other selections. |
question.set(index);
|
Applies to both question types. For Single Choice questions, this function sets a new selection and unsets the current selection. For Multiple Choice questions, this function sets a new selection but does not clear other selections. |
question.set(index,openEnd);
|
Applies to both question types. For Single Choice questions, this function sets a new selection and unsets the current selection. For Multiple Choice questions, this function sets a new selection but does not clear other selections. openEnd refers to other specify responses. |
question.get(index);
|
Returns an object that has this schema:
The default value is
Possible values for selected are true or false. openEnd refers to other specify responses. |
question.unset();
|
Unsets the value so that there is a default no value state for the question. Clears other specify responses as well. All choices will have this schema:
|
question.unset(index);
|
Applies to both question types. Unsets the value so that there is a default no value state for the question. Clears other specify responses as well. |
question.unset([index,...]);
|
Applies to Multiple Choice questions. Unsets the value so that there is a default no value state for the question. Clears other specify responses as well. |