Hi all,
I have been follwoing responses by TomG to several questions about calculating age from a given DOB and it seems to work for everyone However, none of mine seem to work. So I am asking for some help. For reference this is the most complete theread I found and a snipet of the code bellow: https://www.qualtrics.com/community/discussion/1397/javascript-to-calculate-users-age-based-on-dob-check-age-eligibility-provide-validation-alert/p2
Qualtrics.SurveyEngine.addOnPageSubmit(function() {
var age = moment().diff(moment(jQuery("#"+this.questionId+" .InputText").val()), 'years');
Qualtrics.SurveyEngine.setEmbeddedData('age', age);
if(age > 18) Qualtrics.SurveyEngine.setEmbeddedData('eligible', '1');
});
My embedded variables like age and eligible do not seem to update regardless of the DOB I give it. I tried just printing the Embedded Data in a text field, and it just shows me empty space. I had the moment.js link in the header, and I use the exact code as above about calculating difference and setting eligible; I included the embedded data before the actual block of where the question is; I even tried using Day.js as an alternative in a following text segment, using the response of the date input:
Qualtrics.SurveyEngine.addOnload(function()
{
/*Place your JavaScript here to run when the page loads*/
var given_age = dayjs("${q://QID62/ChoiceTextEntryValue}").format("MM/DD/YYYY");
var curr_date = dayjs().format("MM/DD/YYYY");
var age = curr_date.diff(given_age, 'year') ;
Qualtrics.SurveyEngine.setEmbeddedData('age', age);
});
But the embedded data never shows and the branching I try to add at the end . It seems I am missing something compeltely obvious, but JS is on the newer languages for me. Any help would be appreciated!🙂
Calculating age based on DOB - Embedded Data now showing up or updating
Sign up
Already have an account? Login
Welcome! To join the Qualtrics Experience Community, log in with your existing Qualtrics credentials below.
Confirm your username, share a bit about yourself, Once your account has been approved by our admins then you're ready to explore and connect .
Free trial account? No problem. Log in with your trial credentials to join.
No free trial account? No problem! Register here
Already a member? Hi and welcome back! We're glad you're here 🙂
You will see the Qualtrics login page briefly before being taken to the Experience Community
Login with Qualtrics
Welcome! To join the Qualtrics Experience Community, log in with your existing Qualtrics credentials below.
Confirm your username, share a bit about yourself, Once your account has been approved by our admins then you're ready to explore and connect .
Free trial account? No problem. Log in with your trial credentials to join. No free trial account? No problem! Register here
Already a member? Hi and welcome back! We're glad you're here 🙂
You will see the Qualtrics login page briefly before being taken to the Experience Community
Login to the Community
Welcome! To join the Qualtrics Experience Community, log in with your existing Qualtrics credentials below.
Confirm your username, share a bit about yourself, Once your account has been approved by our admins then you're ready to explore and connect .
Free trial account? No problem. Log in with your trial credentials to join.
No free trial account? No problem! Register here
Already a member? Hi and welcome back! We're glad you're here 🙂
You will see the Qualtrics login page briefly before being taken to the Experience Community
Login with Qualtrics
Welcome! To join the Qualtrics Experience Community, log in with your existing Qualtrics credentials below.
Confirm your username, share a bit about yourself, Once your account has been approved by our admins then you're ready to explore and connect .
Free trial account? No problem. Log in with your trial credentials to join. No free trial account? No problem! Register here
Already a member? Hi and welcome back! We're glad you're here 🙂
You will see the Qualtrics login page briefly before being taken to the Experience Community
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.
