Justin Justin - 1 year ago 250
Javascript Question

On Qualtrics, how to save embedded data with javascript (given that qualtrics has recently been updated and an old SO solution no longer works)

A few months ago I used the excellent advice over here to create a survey in Qualtrics with some javascript code that saved people's responses (given by moving a slider) as embedded data. It all hinges on being able to call some functions when the "Next" button is clicked, as is found under

$('NextButton').onclick = function (event)
in the above link.

I wanted to reuse that survey this weekend, and found that the data was no longer being saved. After fiddling around a bit, I realised that currently, any such function will now only be run the first time the "next" button is clicked, and not on any subsequent time. In other words, precisely the same javascript will either work or do nothing depending on whether it happens to be the first time the next button is clicked.

I mailed Qualtrics asking for advice, and their support person mailed back with the following:

The old application that ran our surveys would reload the page each time you went to a new page in the survey. The current application that runs our surveys is a one page app and going to the next page in a survey does not refresh that entire page, it just presents a different section.

I couldn't find anything on the Qualtrics website giving more information about the aforementioned update, or indicating whether there's a new CSS selector that could be used to select the currently-displayed "next" button, replacing $("NextButton"), and I have no idea how to reverse engineer a Qualtrics survey web page to work it out for myself.

Can anyone suggest how the code in the linked answer above might be altered to work on the updated Qualtrics platform? Or can anyone confirm whether their old code still works, in which case I'm mis-identifying what the problem is.

I have insufficient reputation to comment on the above-linked solution to point out this issue, but perhaps someone else could do so. I'll update this if I get any more information from Qualtrics support.

Answer Source

I haven't tried T. Gibbon's Q_JFE=0 suggestion above, and the suggestion to hide the Next button didn't work for me (though it's possible this was just because I did it wrong - perhaps someone could comment if it worked for them).

When I mailed Qualtrics, their suggestion was to add an event listener as follows, and then remove it before applying another.

document.getElementById('NextButton').addEventListener(function (event) {

However, since I'm just a psychologist who wants to get data quickly rather than a javascript programmer, I wasn't sure just how to go about 'removing an event listener', and decided to try what I thought was a simpler solution, that relies more on Qualtrics embedded data and less on javascript.

For each question that contains a slider whose data I want to save (I had just one such question per page), I included the following, to save the ID for that particular question as embedded data. Each question's ID is saved with a unique tag ('q1ID' in the following). I had one such question per page.

Qualtrics.SurveyEngine.setEmbeddedData('q1ID', this.getQuestionInfo().QuestionID);

Then once all the slider-type questions had been presented, on the following page I included this code:

    var tags = ['q1','q2', 'q3'];

    var pipedStrings = {'QID356':'${q://QID356/TotalSum}',

    tags.forEach(function(tag) {
        var qID = Qualtrics.SurveyEngine.getEmbeddedData(tag + 'ID');
        var response = pipedStrings[qID];
        Qualtrics.SurveyEngine.setEmbeddedData(tag, response);


Initially, I'd tried what I thought was more sensible:

tags.forEach(function(tag) {
        var qID = Qualtrics.SurveyEngine.getEmbeddedData(tag + 'ID');
        var response = '${q://' + qID + '/TotalSum}';
        Qualtrics.SurveyEngine.setEmbeddedData(tag, response);


But as pointed out here, Qualtrics won't allow you to fetch data by concatenating a variable into a string like this. Consequently, even though it seems a ridiculously roundabout what to do it, I created the pipedStrings object that has a list of all the question IDs I needed (which I found by exporting the survey to a text file and searching for my question tags).

This allowed me to save the responses to slider questions as embedded data, with the keys listed in tags. If anyone has a simpler approach, avoiding have to create the dictionary of pre-formatted strings, please do comment.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download