This script will allow a participant to enter responses in an Allocation Grid question, or opt out by selecting an exclusive checkbox, but not both.
Note:
- <span">When naming pages and questions, please ensure that the names do not start with the same name followed by an underscore, e.g. Q1_Name_allocation and Q1_Name_page. Naming the questions like this will cause the script to not work in mobile. </span">
- If the question property Minimum Value is set to be greater than 0 and the Default Value is left blank, the script will not work on mobile. A workaround is to set the Default Value to 0 where a Minimum Value greater that 0 is required.
Detailed Steps
Adding and setting up the Questions:
- Click on the Questionnaire tab of your survey.
- Create a page.
- Create your Allocation Grid question within the page, with the required number of rows.
- Deselect Question completion required in the properties of the Allocation Grid question.
- Remove the 0 from the Default value field in the properties of the Allocation Grid question.
- Change the Minimum total field in the properties of the Allocation Grid question to 0.
- Change the Maximum total field in the properties of the Allocation Grid question to 9999.
- Create a Multi Choice question within the page. It can be the first item on the page, or the last item (depending on your preference).
- Deselect Question completion required in the properties of the Multi Choice question.
- Remove the default instruction text from the multi choice question.
- Add one answer to the Multi Choice question (e.g. "Don't know", "Not Applicable", "Prefer Not to Answer").
Prepare the script in Notepad:
- Open Notepad or a similar text editing tool.
- Copy the script below into Notepad.
- Change ALLOC_GRID to the name of your Allocation Grid question.
- Change CHECKBOX to the name of your multi choice question.
- Save the completed script in Notepad.
Script:
/* Script Name: How do I add an exclusive check box on a page with an allocation grid 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. */ if (!IsATR){ GridSequence gs = ALLOC_GRID; ChoiceQuestion cq = CHECKBOX; int total = 0; foreach (ShowQuestionAction sqa in gs.WorkflowSteps){ VerbatimQuestion vq = (VerbatimQuestion)sqa.VerbatimQuestion; if ( vq.IntValue > 0 && sqa.Visible){ total++; } } if ( total>0 && cq.SelectedAnswer != null){ NewError("The checkbox must be exclusive, please remove all answers you have typed in."); return; } if ( total<=0 && cq.SelectedAnswer == null){ NewError("Please complete this question."); } }
Insert the completed script into the Script section of your Page:
- Copy the completed script from Notepad.
- Select the Page in the Questionnaire Tree.
- In the Scripting section of the Page, click Edit Scripts.
- Paste the script into the On Validate tab.
- Click Save.
- Validate and test your survey.
Comments
0 comments
Article is closed for comments.