I know this question has been asked many times, but I've researched and tried everything and for some reason this still isn't working for me - trying to assign an embedded data field called UserAge from a question getting birthday in the format MM/DD/YYYY.
1. I've set an embedded data field, UserAge at the start of my survey flow.
2. I've placed a block below with the question asking for birthday, with the following JS:
Qualtrics.SurveyEngine.addOnPageSubmit(function() {
var age = moment().diff(moment(jQuery("#"+this.questionId+" .InputText").val()), 'years');
Qualtrics.SurveyEngine.setEmbeddedData('UserAge', age);
});
Have also tried the different codes on this thread (and looked at other threads as well):
https://www.qualtrics.com/community/discussion/1397/javascript-to-calculate-users-age-based-on-dob-check-age-eligibility-provide-validation-alert/p1
3. After the block, I have a "Then" branch based on UserAge (if under 18, terminate).
Am I missing anything? For some reason, I can't get UserAge to write from setEmbeddedData. Using alerts, I can see that no value is being assigned to it.
Side note - I also want to create additional variables from birthday - (1) birth year, and (2) age groups (e.g. a variable called age group with categories of 18-30, 30-50, 50-70, 70+).
Any help would be much appreciated! New to JS and survey flow programming.
Thanks!
Set Embedded Data Not Working - Get Age from Birthday and Assign Age Group
Best answer by AnnaH
Got it to work, thanks - forgot to load in the header. It's not letting me accept your answer unfortunately but thank you!
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.
