This script will validate a page containing one or more Open End questions as well as an opt-out exclusive option. It will ensure that the participant types their responses into at least one text box, or select the checkbox, but not both.
If the participant enters responses into the text boxes only, the script also ensures that the answers are entered in order of the boxes.
Note: This script only works if there is only one exclusive option on the page, and this exclusive option is the very last item. The script is also ignored by ATR, so ATR data will not follow these validation rules - the setup will need to be checked manually through the test link.
Example
You are asking participants to type in the names of up to ten financial institutions they have heard of before. You also want to provide an opt-out checkbox with the option "Can't think of any names right now."
Detailed Steps
Creation and Setup of Questions
- Click the Questionnaire tab of your survey.
- Create a Page.
- Create an Open End question within the Page.
- Deselect Question completion required in the properties of the Open End question and delete the default instruction text from the question.
- Duplicate the Open End question as many times as required and rename each question as necessary.
- Ensure all of the Open End questions are within the Page.
- Create a multi choice question (either standard or visual) within the page and add the opt-out text as an answer option. Using the example above, the answer option will be "Can't think of any names right now".
- Ensure the multi choice question is the last item on the page.
- Deselect Question completion required in the properties of the multi choice question and delete the default instruction text from the question.
- Create a single choice question and name it ERR_MSG. If this question already exists, do not create a new one.
- Ensure that ERR_MSG is not seen by respondents by hiding it and dragging it to the end of the questionnaire tree (anywhere after the completion point of your study).
- Add this answer option to ERR_MSG: Please complete the question. and update the precode to no_resp.
This error message will be seen if the respondent doesn't answer the question (i.e. doesn't select the opt-out option AND doesn't type any responses in the text boxes). - Add another answer option to ERR_MSG: Please enter one response only. and update the precode to one_resp.
This error message will be seen if the respondent selects both options (i.e. selects the opt-out option AND types in at least one response in any of the text boxes). - Add another answer option to ERR_MSG: Please type in your answers in order of the boxes provided. and update the precode to ans_in_order.
This error message will be seen if the respondent types more than one response in one or more text boxes, but leaves blank boxes in between answers.
Note: The script pipes in error messages from this ERR_MSG question, so you can update the error messages to your liking without affecting the script.
Note: If you have multiple languages in your survey, simply translate the ERR_MSG question and the script will pipe in the error messages based on the current survey language.
Script Preparation
- Copy the script below into Notepad or any other text editor (e.g. Notepad++, Textpad).
- Change QNAME_DK to the name of your multi choice question.
- Change QNAME_PG to the name of your page.
Script
/* Script Name: How do I add an exclusive check box on a page with multiple open end 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. */ if (!IsATR){ int text_count=0; List <bool> vq_value = new List<bool>(); ChoiceQuestion dk = QNAME_DK; foreach (IClientSideWorkflowStep wfs in QNAME_PG.WorkflowSteps){ //the current question is a show question action if (wfs is ShowQuestionAction){ ShowQuestionAction sqa = (ShowQuestionAction)wfs; //the current question is a verbatim question if (sqa.VerbatimQuestionId != Nulls.NumberNull){ VerbatimQuestion vq = (VerbatimQuestion)sqa.VerbatimQuestion; if (vq.Value!=null) { text_count++; vq_value.Add(true); } else { vq_value.Add(false);} } } } if (text_count==0 && (dk.SelectedAnswer == null)) { NewError(((Answer)ERR_MSG.FindAnswerByCode("no_resp")).Html); return; } else if (text_count>0 && (dk.SelectedAnswer != null)) { NewError(((Answer)ERR_MSG.FindAnswerByCode("one_resp")).Html); return; } if (text_count>0) { for (int i=1; i<(vq_value.Count); i++){ if (!vq_value[i-1] && vq_value[i]){ NewError(((Answer)ERR_MSG.FindAnswerByCode("ans_in_order")).Html); return; } } } }
Script Usage
Insert the completed script into the Script section of the page by doing the following:- 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.
More Information
For more information, see our webhelp topics:
Comments
0 comments
Article is closed for comments.