Page manipulation in scripting
Use the page object to manipulate the page at the last stage of the responding engine. At this point, survey logic, piping, localization, and randomization and rotation have all already occurred.
- The page is a separate root object passed to the onLoad function and can only occur onLoad. Accessing the page object from onComplete will cause an error.
- You cannot hide elements that do not have names. Currently Divider elements do not support names, so they are not scriptable.
- Page customization is visual only. Hiding the question does not skip the question. Instead, it marks the question as not required if the question was set to required.
- The page is still rendered for survey respondents even if all elements in it are removed or hidden.
- Hidden elements (for example, masked answer options or survey elements hidden through survey logic) cannot be accessed through scripting.
Page elements
Here, "page elements" refer to named survey components on survey pages that are visible on the responding side. This includes:
- Questions
- Text and Image, Media Player, and Embedded Content elements
- End Survey and Profile actions
Function or property | Description |
---|---|
page.getElement("elementName");
|
Returns an element within the page by name. |
element.name
|
Read-only property. The name of the element within the page. |
element.hide();
|
Hides a question or element within the
page.
Note: If all questions on a page are hidden, the entire page
will be skipped. Respondents will proceed directly to the subsequent page.
|
Example |
---|
In this function example, the question named City is hidden.
|
Child elements
Here, "child elements" refer to the elements within page elements, such as answers, Grid question statements, and Allocation and Rank Order items. The following question types have child elements:
- Single Choice
- Multiple Choice
- Single Choice Grid
- Multiple Choice Grid
- Allocation
- Rank Order
You can access child elements through the
elements
property (visual order) or by using the
getElementByAuthoredIndex
method. Accessing child
elements in anything other than the question types listed above will result in
a runtime error.
Function or property | Description |
---|---|
element.elements
|
The list of child elements within the page element. |
element.getElementByAuthoredIndex(index)
|
Returns a child element by authored index.
Zero-based.
Note: This method will return
undefined if the index value is incorrect,
or if an answer is hidden in any of the following ways:
|
grid.elements[0]
|
Applies to Grid questions. References the answers. Zero-based. |
grid.elements[1]
|
Applies to Grid questions. References the statements. Zero-based. |
- If all answers in a question are hidden, the entire question will be hidden.
- In Grid questions, if all rows or all columns are hidden, the entire question will be hidden.
Example |
---|
In this function example, the first authored choice for the Single Choice question City is hidden.
|
Example |
---|
In this function example, the first rendered choice for the Single Choice question City is hidden.
|
Example |
---|
In this function example, the first authored answer option is hidden for all statements in the Grid question favoriteMovieGrid.
|
Example |
---|
In this function example, the second rendered statement is hidden in the Grid question favoriteMovieGrid.
|