I have java script in a Lifecycle survey to convert birth date to an age category. The script works perfectly in the older survey layouts, but no in the Simple. I know my code works as it’s been tested. My JS
Qualtrics.SurveyEngine.addOnReady(function()
{
/*Place your JavaScript here to run when the page is fully displayed*/
var current_date = "${date://CurrentDate/DS}";
var current_year = current_date.substr(0,4);
var dateOfBirth = "${e://Field/BirthDate}"; // 28/05/1970
var dateOfBirth_year = dateOfBirth.substr(6,4); // takes 4 characters counting from the 6th character so would retunr 1970
// var dateOfBirth_year = "${e://Field/Year Of Birth}"; // Used if the year is stored
var captureAge = parseInt(current_year) - parseInt(dateOfBirth_year);
var ageGroup;
// Set group value for ageGroup
if (captureAge < 20) {
ageGroup = "a. younger than 20 years";
} else if (captureAge < 30) {
ageGroup = "b. 20 - 29 years";
} else if (captureAge < 40) {
ageGroup = "c. 30 - 39 years";
} else if (captureAge < 50) {
ageGroup = "d. 40 - 49 years";
} else if (captureAge < 60) {
ageGroup = "e. 50 to 59 years";
} else if (captureAge > 60) {
ageGroup = "f) 60 years and older";
};
var surveyMonth = moment().format('MMMM');
var surveyYear = moment().format('YYYY');
Qualtrics.SurveyEngine.setEmbeddedData('Survey Month', surveyMonth);
Qualtrics.SurveyEngine.setEmbeddedData('Survey Year', surveyYear);
Qualtrics.SurveyEngine.setEmbeddedData('Age Group', ageGroup);
And the script in the Look & Feel>.Header: <script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.3/moment.js"></script><script>
moment().format();
</script>
I have completed surveys in a project with the above script and when i change the layout to older versions, the data captures correctly in the D&A tab, but when I change back to Simple Layout, its blank. HELP!