This script limits the number of characters typed into an Open End text box by showing an error message to participants when they click next.
Example
Detailed Steps
- Copy the script below into Notepad or any other text editor (e.g. Notepad++, Textpad).
- Change Q_OPENEND_1, Q_OPENEND_2 to match the names (case-sensitive) of your open end questions you have on the same page separated by a comma. If you only have one question, just include one without any commas. E.g. VerbatimQuestion[] vqs = { Q_OPENEND };
- Change ###, ### to the number of maximum characters you want to limit each question response in the same order that you specified question names in step 2.
- Insert the completed script into the Script section of the Page/Open End question by doing the following:
- Select the Page/Open End question in the Questionnaire Tree.
- In the Scripting section of the page, click Edit Scripts.
- Paste the script into the OnValidate tab.
- Click Save.
- Validate and test your survey.
Script
/* Script Name: How do I ensure a text response does not exceed X number of characters? 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. */ VerbatimQuestion[] vqs = {Q_OPENEND_1, Q_OPENEND_2}; int[] max = {###, ###}; if(!IsATR){ for(int i = 0; i < vqs.Length; i++){ VerbatimQuestion vq = vqs[i]; string inp = vq.StringValue.Trim(); if(inp.Length > max[i]){ NewError(vq, "Please make sure your answer does not exceed " +max[i]+ " characters."); } } }
Comments
0 comments
Article is closed for comments.