Ask date of birth then compute for age to screen respondents based on age | XM Community
Skip to main content

Dear Qualtrics community,

I saw a couple of posts about asking respondents for their date of birth then age will be computed. Unfortunately, I cannot follow the responses as I have no experience in java script coding. Is there a way you can help me? This is what I want to achieve.

  1. In my screening question block, I want to ask for the date of birth of the respondent.
  2. Then, I want age to be computed automatically from the date of birth. It does not matter if this will appear to the respondent or not.
  3. If the respondent is below 18 or above 60, I will redirect that respondent to end of survey.

I will be really grateful if you can help me on this. Thank you.

 

With kind regards,

Roland

This should help.


This should help.

Hi @Deepak ,

I checked this earlier and I do not follow.

  1. How do I know the question ID?
  2. When I try to embed data using survey flow, it does not detect UserAge.

Thanks.


You can pipe the value somewhere else in rich content editor of that text entry and later copy paste it in that code.

UserAge will autofill from Javascript


You can pipe the value somewhere else in rich content editor of that text entry and later copy paste it in that code.

UserAge will autofill from Javascript

Hi @Deepak ,
I inserted this code in the java script of the question at hand.

 

Qualtrics.SurveyEngine.addOnReady(function()
{
    
var current_date = "${date://CurrentDate/DS}";
    var year1 = current_date.substr(0, 4);
    var Qyear = "${q://QID26/ChoiceTextEntryValue}";
    var captureAge = parseInt(year1) - parseInt(Qyear);
    Qualtrics.SurveyEngine.setEmbeddedData('UserAge', captureAge);

});

When I got to survey flow → embedded data → Existing Embedded Data → “No Items Available”

Does this mean UserAge was not created successfully?


You need to manually create UserAge embedded data in survey flow the value of it will be auto populated. 


Leave a Reply