Need a question where I calculate age from date of birth. I was using a date picker but it was too complicated when I've got to translate it into four languages with limited javascript knowledge. I am therefore currently using a side by side question with three text inputs for dd, mm and yyyy. This is the code I have so far to calculate the age but it is not working.
Qualtrics.SurveyEngine.addOnReady(function()
{
var day = parseInt("${q://QID87%231/ChoiceTextEntryValue/1/1}");
var month = parseInt("${q://QID87%231/ChoiceTextEntryValue/1/2}") - 1;
var year = parseInt("${q://QID87%231/ChoiceTextEntryValue/1/3}");
var todayInSeconds = new Date().getTime();
var birthdayInSeconds = new Date(year, month, day);
var ageInSeconds = todayInSeconds - birthdayInSeconds;
var ageInYears = Math.floor(ageInSeconds / (1000 * 3600 * 24) / 365);
Qualtrics.SurveyEngine.setEmbeddedData("Age", ageInYears);
}
Any help would be greatly appreciated. Thank you
Leave a Reply
Rich Text Editor, editor1
Editor toolbars
Press ALT 0 for help
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.