This is a 2-part setup which involves first inserting a text box into the the last row, first column of one of the following standard Grid questions:
- Single Choice Grid
- Multi Choice Grid
- Rank Order Grid
The second script will then check the response selected in the last row of the grid. If there is a response, the respondent will be required to type something in the box. If there is no response, the box should be empty before continuing in the survey.
Notes:
- This script will not work for visual questions. It will also not work in mobile view because of the use of JavaScript.
- The script makes the last row optional.
- For Single Choice Grid, respondents is not allowed to deselect an item in the grid.
Detailed Steps
Adding and setting up the questions:
- Click on the Questionnaire tab of your study.
- Create a page.
- Create your standard grid question within the page.
- Deselect "Question completion required" in the properties of the grid question.
- Create an open end question within the same page.
- Remove the default instruction text from the open end question.
- In the Properties section of the open end question, deselect "Question completion required".
- In the Properties section of the open end question, change the "Width" property to 25.
Prepare the scripts in Notepad:
- Open Notepad or a similar text editing tool.
- Copy Script 1 below into Notepad.
- Change GRIDNAME to the name of your standard grid question.
- Change TEXTBOXNAME to the name of your open end question.
- Save the completed script in Notepad.
- Copy Script 2 below into Notepad.
- Change GRIDNAME to the name of your standard grid question.
- Change TEXTBOXNAME to the name of your open end question.
- Save the completed script in Notepad.
Script 1:
<script src="https://static.visioncritical.net/prog/ext_libs/jquery/jquery-1.12.3.min.js" type="text/javascript"></script> <SCRIPT src="https://static.visioncritical.net/prog/s1/js/common/common_v1.560.js"> /* Script Name: How do I insert a text box to the last row of a standard 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. */ </SCRIPT> <SCRIPT> appendTextBoxToLastRow_Grid([%(GRIDNAME.Id)%],"[%(TEXTBOXNAME.Id)%]"); </SCRIPT>
Script 2:
/* Script Name: How do I insert a text box to the last row of a standard 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 = GRIDNAME; VerbatimQuestion vq = TEXTBOXNAME; // No need to edit below int other_row = gs.WorkflowSteps.Count; bool row_checked = false; bool other_answered = false; foreach(ShowQuestionAction sqa in gs.WorkflowSteps){ ChoiceQuestion cq = (ChoiceQuestion)sqa.ChoiceQuestion; int i = sqa.OrderInParent+1; if ( (int)cq<1 && i!=other_row){ NewError("Please enter a response for each row. The last row is optional."); break; } if ( (int)cq>0 && i==other_row){ row_checked = true; } } if (vq.Value!=null) other_answered = true; if (row_checked==true && other_answered==false){ NewError("Please type your response in the box provided."); } if (row_checked==false && other_answered==true){ NewError("Please select a response for the last row (since you have typed something into the box)."); } }
Insert the completed scripts into the Script section of your Page:
- Copy the completed Script 1 from Notepad.
- Select the Page in the Questionnaire Tree.
- In the Scripting section of the Page, click Edit Scripts.
- Paste Script 1 into the JavaScript tab.
- Paste Script 2 into the On Validate tab.
- Click Save.
- Validate and test your survey.
Notes:
- ATR will bypass the validation script, so please be aware that ATR data will not be accurate for this setup. It will need to be checked manually through the link.
- Please contact Technical Support if you would like to apply the scripts in a multi-language survey.
More Information
For more information, please see our WebHelp topics:
Comments
0 comments
Article is closed for comments.