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 the previous question. The question that will be masked will be referred to as the masking question.
This script will work in following question types:
- Allocation Grid/Slider to Choice Question
- Allocation Grid/Slider to Grid Question - Rows
- Allocation Grid/Slider to Page Items
Use Case
Show activities that a respondent spends only 0-20% of the time per day in Q2.
Q1
Q2
This script will work in following question types:
Previous Question Type | Masking Question Type |
|
|
Detailed Steps
Note: Make sure that the options in the previous question and in the masking question have the same number of items and are in the same order.
- Copy the script 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.
- Change min to the lower bound of a number range you would like to show in masking question.
- Change max to the upper bound of a number range you would like to show in masking question.
- 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.
- Click Save.
- Validate and test your survey.
Script
/*Script Name: How do I pipe / hide / mask columns in a Grid question based on a previous Choice question? (Power Surveys)
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(GetAllocRowsIfBetween(Q_PREVIOUS, min, max), new int[]{-1}));
Use Case Example
Show (Q2, ArrayUnion(GetAllocRowsIfBetween(Q1, 0, 20), new int[]{-1}));
Do you anticipate that there will be cases where participants are shown only one option as a result of masking?
The survey logic might end up forcing participants 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.