This script will ensure that the maximum number of responses allowed in a Multi Choice question is based on one of the following:
- the number selected in a previous Single Choice question.
- the number of items selected in a previous Multi Choice question.
- the number entered in a previous Numeric question.
Note: This script will work on both standard and visual questions.
Examples
- You have a Single Choice question called Q1 that asks respondents how many vehicles they own (response options are 1,2,3,4,....,10). You then have a follow up Multi Choice question called Q2 that asks what type of vehicles the respondent owns and shows a list of over 10 types of vehicles (convertible, sports car, pick up truck, SUV etc). The number of responses selected at Q2 cannot exceed the number selected at Q1.
- Continuing from example 1, you have a Multi Choice question called Q3 that follows Q2 and asks respondents which vehicles they bought in the last 5 years. If a respondent selected 4 types of vehicles at Q2, then the maximum number of responses allowed at Q3 should be 4.
- You have a Numeric question called Q_Shop that asks respondents to type in how many times they shopped at a drug store in the past 3 months. You then have a follow up Multi Choice question called Q_Stores that asks respondents to choose the drug stores they shopped at in the past 3 months, from a list of over 20 drug stores. The number of responses selected at Q_Stores cannot exceed the number entered at Q_Shop.
Detailed Steps
- Create your first question as required. This can be a Single Choice question, Multi Choice question or Numeric question (standard or visual). This will be referred to as the source question.
- In example 1 above, Q1 is the source question.
- In example 2 above, Q2 is the source question.
- In example 3 above, Q_Shop is the source question.
- Create your second question as required. This must be a Multi Choice question (standard or visual). This will be referred to as the "multi" question.
- In example 1 above, Q2 is the multi choice question.
- In example 2 above, Q3 is the multi choice question.
- In example 3 above, Q_Stores is the multi choice question.
- Copy the script below into Notepad or any other text editor (e.g. Notepad++, Textpad).
- Change Q_SOURCE to the name of your source question.
- Change Q_MULTI to the name of your multi-choice question.
- Insert the completed script into the Script section of your multi question by doing the following:
- Select your Multi Choice question in the Questionnaire Tree.
- In the Scripting section of the question, click Edit Scripts.
- Paste the script into the On Load tab.
- Click Save.
- Validate and test your survey.
Note: The question names used in scripts are case-sensitive. Ensure that you use the exact question names as they appear in the Questionnaire tree of the study.
Script
/* Script Name: How do I restrict the number of Multi Choice selections based on a previous 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. */ IOrderable source_question = Q_SOURCE; ChoiceQuestion multi_question = Q_MULTI; /******* DO NOT MODIFY BELOW *******/ int max=0; if (source_question is ChoiceQuestion) { ChoiceQuestion cq = (ChoiceQuestion)source_question; if (cq.IsSingleChoice) max=(int)cq; else max=cq.GetSelectedAnswers().Length; } else max=((VerbatimQuestion)source_question).IntValue; multi_question.MaximumAnswers = max;
More Information
For more information, see our webhelp topics:
Comments
0 comments
Article is closed for comments.