Grid questions in scripting

Use scripting to get and set values for Grid questions.

The functions in this topic apply to the following question types:

  • Single Choice Grid
  • Multiple Choice Grid
Table 1. Grids
Function Description
question.getItems() Gets an array of statement objects.
question.unset(); Unsets the value so that there is a default no value state for the question.
Table 2. Items
Function or property Description
item.index; A read-only property that reflects the authored index of the statement.
item.getSelectedIndex(); Returns the index of the selected choice. This value is zero-based. For a Single Choice Grid, this returns -1 if no item is selected.
item.getSelectedIndexes(); Returns a list of selected indices. Returns an empty array if no item is selected.
item.set([index, …]); Applies to Multiple Choice Grids. Zero-based, so if you select the first two choices, the array is 0 and 1. Does not clear other selections.
item.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.
item.get(index);

Returns an object that has this schema:

{ selected: }

Possible values for selected are true or false.

item.unset(); Resets the statement response.
item.unset(index); Applies to both question types. Unsets the value so that there is a default no value state for the item.
item.unset([index, ...]); Applies to Multiple Choice Grids. Unsets the value so that there is a default no value state for the item.