This script ensures a participant's answer is within certain time frame from current date. If the participant attempts to click Next without entering a valid date answer, an error message will be shown.
Example
You want to ask participants "Within past 3 months, when did you see this advertisement?" You need to ensure the participant's answer is within the last 90 days.
Detailed Steps
- Copy the script from below.
- Select the date question in the Questionnaire Tree.
- In the Scripting section of the question, click Edit Scripts.
- Paste the script into the On Validate tab.
- Change Q_DATEQUESTION to the name of your date question.
- Change 30 to the number of days you would like to allow from today.
- Change error message inside double quotation marks "red text" as required.
- Click Save.
- Validate and test your survey.
Script:
/*Script Name: How do I ensure a participant's input is within past X days/months? (Power Surveys)
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){ VerbatimQuestion vq = Q_DATEQUESTION; int pastXdays = 30; string errorMsg = "Please enter a valid date."; //------- DO NOT MODIFY BELOW ------- DateTime now = DateTime.Now; DateTime entered = vq.DateTimeValue; if(entered.AddDays(pastXdays) < now || entered > now){ NewError(errorMsg); } }
More Information
For more information, see our webelp topic Date question.
Comments
0 comments
Article is closed for comments.