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
Page 1 / 1
Hi @Sarah646,
You can use DOB question from Qualtrics library and use embedded data to create age buckets.
Thanks,
Bhushan
You can use DOB question from Qualtrics library and use embedded data to create age buckets.
Thanks,
Bhushan
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.