Use scripting to reorder child elements in questions.
You can reorder child elements in the following question types:
- Single Choice
- Multiple Choice
- Single Choice Grid
- Multiple Choice Grid
- Allocation
- Rank Order
| Function or property | Description |
|---|---|
|
Sets the order of child elements based on the authored indexes (zero-based), and returns an array with all the elements' authored indexes. If the authored index is not present in the array because of masking or any other reason, it will be ignored. If the number of authored indexes provided is less than the number of elements in the array, the first matches will be ordered first. |
| Function or property | Description |
|---|---|
|
Reorders answers (zero-based).
grid.elements[0] references the answers.
|
grid.elements[1].reorderElements([...])
|
Reorders statements (zero-based).
grid.elements[1] references the statements.
|
grid.reorderElements([...]) to reorder the entire grid.
You can only use
grid.elements[0] or
grid.elements[1] to reorder answers or statements,
respectively.
Example
A Single Choice question has 5 answer options. 2 answers are masked. The zero-based authored indexes range from 0 to 4.
| Single Choice question |
|---|
|
a - 0 b - 1 (Masked) c - 2 d - 3 (Masked) e - 4 |
| Function example | Description |
|---|---|
q1.reorderElements([]); // returns
[0,2,4]
|
Passing an empty array returns the current order of elements. |
q1.reorderElements([1,0,3,4]); // returns
[0,4,2]
|
This function example reorders the answers as b, a, d, and e. Because b and d are masked, a and e are returned. 2 was not provided, so answer c appears at the end of the array. |
q1.reorderElements([2]); // returns [2,0,4]
|
2 (answer c) is set at the beginning of the array. The remaining non-masked answers a and e appear at the end of the array. |