This setup is intended to check that a respondent enters their correct age by asking them twice. First, the respondent will see a numeric question where he/she types in his/her age. Then, the respondent will see a date question (at any point later in the survey such as in the Demo section at the end for example) and will have to enter his/her date of birth.
The script calculates the age based on the date of birth, then compares it to the age that was entered. If the ages don't match, we flag this respondent.
Detailed Steps
- Create a Numeric question that asks the respondent to type in their age.
- Create a Date question that asks the respondent to enter their date of birth.
This Date question must be asked at any point later in the survey, after the Numeric question is asked. - Create a Single Choice question to act as the flag for cases where the typed in age doesn't correspond to the date of birth.
- Make sure this question has one answer option only (e.g "Age/DOB mismatch").
- Make the Single Choice question hidden.
- Click Save to save the changes.
- Copy the script below into Notepad or any other text editor (e.g. Notepad++, Textpad).
- Change NUMERIC_NAME to the name of your Numeric question.
- Change DATE_NAME to the name of your Date question.
- Change FLAG_Q to the name of your straight-line flag (Single Choice Question).
- Insert the completed script into the Script section of the date question by doing the following:
- Select the Date question in the Questionnaire Tree.
- In the Scripting section of the page, click Edit Scripts.
- Paste the script into the On Validate tab.
- Click Save.
- Click Validate and test your survey.
Script
/* Script Name: How do I validate the age of a respondent by asking their age as well as date of birth? 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. */ ChoiceQuestion flag = FLAG_Q; VerbatimQuestion age = NUMERIC_NAME; VerbatimQuestion date = DATE_NAME; int age_asked = age.IntValue; int age_calculated = Panelist.Age(date.DateTimeValue); Unset (flag, (int) flag); if (age_asked!=age_calculated) Set(flag, 1);
Note:
- The hidden Single Choice question can now be used in a panel filter to disqualify the respondent or for some other type of routing.
More Information
Please click the WebHelp links below for more information:
Comments
0 comments
Article is closed for comments.