Java script has stopped working - looking for ideas why | Experience Community
Skip to main content
Question

Java script has stopped working - looking for ideas why

  • January 21, 2026
  • 2 replies
  • 24 views

Forum|alt.badge.img+1

Hi Brains Trust

I have some java script in a survey that calculates the respondent’s age and the age they will be at a specific date in the future from their date of birth. This is then used as embedded data to govern how they move through the survey.

This was working fine before Christmas but have returned from the break to find it is no longer working at all (no edits have been made to any part of the survey). Info on Qualtrics product updates doesn’t shed any light on this. I’ve contacted my organisation’s IT security area to see if any updates have been made there to prevent it running - that is a possibility as it previously didn’t work when on the network but worked when completing the survey on a personal device (which is what real life would be as it’s a consumer survey). But now it doesn’t work on any device at all. I am not using Simple Layout.

Has anyone experienced anything like this before? And, more importantly, does anyone have any ideas on why? I’m not a developer and had to copy and paste the code from somewhere else.

Thanks in advance.

2 replies

Forum|alt.badge.img

Hi KazJPat

This works for me, I hope it works for you too. The only input you need is the user's date of birth. Put this code in the first question of the survey.

 

Qualtrics.SurveyEngine.addOnload(function()
{
/* Place your JavaScript here to run when the page loads */
/* Retrieve date of birth from Embedded Data */
var birthDateString = "${e://Field/birthDate}";
if (birthDateString) {
var birthDate = new Date(birthDateString);
var today = new Date();
// 1. Verify that the date is valid before calculating
if (!isNaN(birthDate.getTime())) {
// 2. Age calculation using calendar logic
var age = today.getFullYear() - birthDate.getFullYear();
var m = today.getMonth() - birthDate.getMonth();
var d = today.getDate() - birthDate.getDate();
// 3. Adjustment: If the birthday month or day has not yet arrived, subtract 1
if (m < 0 || (m === 0 && d < 0)) {
age--;
}
// 4. Save the result in the Embedded Data "Age"
Qualtrics.SurveyEngine.setEmbeddedData("Age", age);
}
}
});

 

Regards.


Forum|alt.badge.img+1
  • Author
  • January 22, 2026

Thanks, I’ll give that a try.