1

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.

Community
  • 1
  • 1
Justin
  • 21
  • 2
  • 8

2 Answers2

2

Qualtrics uses two survey engines: the older SE and the newer JFE. Qualtrics Support was referring to JFE. You can force Qualtrics to use SE by adding the parameter Q_JFE=0 to your survey link. That might be a quick fix.

That said, adding an event listener to the NextButton has never worked reliably with either SE or JFE. Qualtrics has its own event listeners on the Next Button that interfere. The most reliable method is to use JavaScript to hide the NextButton, then add your own button that performs any process you need, then at the end clicks NextButton. See example here.

Community
  • 1
  • 1
T. Gibbons
  • 4,919
  • 2
  • 15
  • 32
1

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) {
doStuff();
});

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, in that it doesn't rely on having some functions run when the 'next' button is clicked.

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:

Qualtrics.SurveyEngine.addOnload(function()
{
    var tags = ['q1','q2', 'q3'];

    var pipedStrings = {'QID356':'${q://QID356/TotalSum}',
        'QID357':'${q://QID357/TotalSum}',
        'QID358':'${q://QID358/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.

Community
  • 1
  • 1
Justin
  • 21
  • 2
  • 8
  • Why not just assign the embedded variables in the survey flow like q1ID = ${q://QID356/TotalSum}? – T. Gibbons Aug 24 '16 at 18:36
  • 1
    This is a more general solution that your suggestion since it allows for question randomization, which I think is common enough practice in psychology surveys to warrant consideration. In my case, for instance, for every block, a random one out of two possible variations of a question is displayed. So the question ID for 'q1' might be QID356 or it might be QID357, depending on which question variant happened to be displayed to the participant. I don't see how assigning it in the survey flow can account for that, but if there is a way to do so, please let me know. – Justin Aug 24 '16 at 19:09
  • 1
    Another reason I needed to do it this way (and again, I think this would be a common enough need) - I need to perform operations on some of the responses, depending on particular conditions being met. For instance, I have to reverse-score some of the questions but not others. – Justin Aug 24 '16 at 19:36
  • 1
    If you randomly show 1 of 2 q1's (that's isn't what the code you posted says) then you can do this in the survey flow: q1 = $e{ q://QID356/TotalSum + q://QID357/TotalSum }. I don't get your second point. Unless there is something you didn't show us, you end up with the same variables with the same values. – T. Gibbons Aug 24 '16 at 20:49
  • Ok, that is a smart way to do it in the survey flow if there's no other difference between the responses. In my case, though, if the second variant of each question is displayed, the response that I want to save is actually 100 minus the given response. So if they responded with 21 to the second version, I want to save their response as 79. Yes, I'm sure I could do this using some version of your suggestion, but the point is that my solution makes it easy for people to do whatever manipulation to the response variable they want - it's easily adaptable to others' needs. – Justin Aug 24 '16 at 21:01
  • If someone had lots of versions of the same question, or if they wanted to apply some complicated function to the response before saving it, or if they wanted to do something with it in addition to saving it as embedded data, my answer will help them, and is thus useful in a general sense. – Justin Aug 24 '16 at 21:05
  • the option to hide the next button from T.Gibbons worked for me – Flo Sep 28 '16 at 10:34