Tip: Are you using scripting with power surveys to pipe/hide/mask answer options from one question to another question? You can now do this in surveys with no need for scripting. For more information, see Carry Forward Answers in the Surveys documentation.
The terms pipe, hide and mask are used interchangeably. The common goal is to show options based on a previous question. We will use the word mask throughout this article.
The question which you would like to reference will be referred to as previous question. The question that will be masked will be referred to as masking question.
This script will work in following question types:
- Choice Question to Choice Question
- Choice Question to Grid Question - Rows
- Choice Question to Page Items
Previous Question Type | Masking Question Type |
|
|
Detailed Steps
Note: Make sure that the options in previous question and in masking question have the same number of items and are in the same order.
- Copy the script of appropriate case from below.
- Select the masking question/page in the Questionnaire Tree.
- In the Scripting section of the masking question/page, click Edit Scripts.
- Paste the script into the On Load tab.
- Change Q_MASKING to the name of your masking question/page.
- Change Q_PREVIOUS to the name of your previous question.
Note: this can appear twice in the script depending on the case. - Change -1 to item numbers you would like to show all the time (separated by a comma if there are multiple). E.g. 'None of these' option. If you do not have any items to show permanently, leave it as is.
Note: the item number represents the position of the item, it is not the precode. - Click Save.
- Validate and test your survey.
Script
Case | Script |
Show selected answers from previous question | /* Script Name: How do I pipe / hide / mask options based on a previous Choice question? To ensure your script works as expected, always copy the original script from the script library found in the support portal. Failure to use the most up to date script from the script library may cause unexpected results. */ Show (Q_MASKING, ArrayUnion(GetSelectedIndexes(Q_PREVIOUS), new int[] {-1})); |
Show unselected answers from previous question | /* Script Name: How do I pipe / hide / mask options based on a previous Choice question? To ensure your script works as expected, always copy the original script from the script library found in the support portal. Failure to use the most up to date script from the script library may cause unexpected results. */ Show (Q_MASKING, ArrayUnion(ArrayDiff(GetAllIndexes(Q_PREVIOUS), GetSelectedIndexes(Q_PREVIOUS)), new int[] {-1})); |
Do you anticipate that there will be cases where respondents are shown only one option as a result of masking?
The survey logic might end up forcing respondents to select the only option or allocate 100% to the only option without any other choices (only in cases of masking question being a Single Choice question or an Allocation Grid). If you would like to skip the question and have the option auto-punched for this specific case, please follow further steps in this article to complete your script.
Comments
0 comments
Article is closed for comments.