This script allows you to mask options selected (or not selected) from 2 or more Choice questions into a follow-up question.
The terms pipe, hide and mask are used interchangeably. The common goal is to show options based on one or more previous questions. 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 with following question types:
Previous Question Type | Masking Question Type |
|
|
Example
Selected answers in Q1 and Q2 are shown in the follow-up question Q3.
Detailed Steps
- Create all your previous questions.
- Create a masking question with full list of items from all previous questions you want to include.
Note: The options in the masking question must list each set of answer options from the previous questions in the order that these questions appear in your survey. - Copy the script below.
- Select the masking question/page in the Questionnaire Tree.
- In the Scripting section of the question, click Edit Scripts.
- Paste the script into On Load tab.
- Change Q_PREV1,Q_PREV2 to the question names you want to reference separated by a comma. e.g. Q1,Q2
- Change Q_MASK to the question name of your masking question/page.
Note: question names are case-sensitive. - Find applicable case for you from below list. Copy the line and replace red text in the script.
- Show selected answers on a Choice question, Grid Rows or Pages:
Note: Do not change the script, Skip to step 9.
- Show selected answers on a Choice question, Grid Rows or Pages:
- Show unselected answers on a Choice question:
Hide((ChoiceQuestion)currQ, sel);
- Show unselected answers on Grid Rows:
Hide((GridSequence)currQ, sel);
- Show selected answers on Grid Columns:
ShowColumns((GridSequence)currQ, sel);
- Show unselected answers on Grid Columns:
HideColumns((GridSequence)currQ, sel);
- Show unselected items on a Page:
Hide((PageSequence)currQ, sel);
- Click Save.
- Validate and test your survey.
Script
/* Script Name: How do I mask options in a question based on two or more choice questions? 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. */ ChoiceQuestion[] prevQ = {Q_PREV1,Q_PREV2}; IOrderable currQ = Q_MASK; ArrayList alist = new ArrayList(); int ind = 1; foreach(ChoiceQuestion cq in prevQ){ foreach(Answer ans in cq.GetOrderedAnswers()){ if(ans.Selected) alist.Add(ind); ind++; } } int[] sel = (int[])alist.ToArray(typeof(int)); Show(currQ, sel);
Comments
0 comments
Article is closed for comments.