The same JavaScript code functions in some places within the survey but not in other places | XM Community
Skip to main content

I've got the following code on various text-only questions throughout a survey. Respondents choose which information they see by answering multiple choice questions, and this code tracks the number and content of information items viewed.
Qualtrics.SurveyEngine.addOnReady(function()
{
var OldSummary = "${e://Field/SummaryText}";
var NewText = this.getQuestionTextContainer().innerText;
var NewSummary = OldSummary + "

  • " + NewText+"
  • ";
    Qualtrics.SurveyEngine.setEmbeddedData('SummaryText', NewSummary)    

    var OldCount = parseInt("${e://Field/CountInq}");
    var NewCount = OldCount+1;
    Qualtrics.SurveyEngine.setEmbeddedData('CountInq', NewCount)    
    });
    I've probably got about 20 instances of this code in my survey, but it's only functioning in 6 instances. In no cases does the code show up twice on the same page, however it is included multiple times in the same block on separate pages. Because it's the exact same code, I don't think the problem is the JavaScript; I think the problem is the way the JavaScript works with Qualtrics.
    I've also considered the following explanations:
    • The code that isn't functioning is mostly in blocks that can show up in multiple places in the survey flow based on branch logic. (The logic is such that respondents will only see the block once, but within the survey flow it shows up multiple times.) The code that is working is mostly not in a branch. However, at least one instance that works is in one of these branched blocks, so I think it's unlikely that the branch logic or duplicate blocks is causing the problem.

    • Character limits on embedded data fields. I don't think this is the problem because 1) I'm only at about ~250 characters when it stops working, and 2) the CountInq variable wouldn't be problematic if the issue was character limits.

    • Page not loading properly, so code that is in ".addOnReady" doesn't execute. To be honest, I'm not sure how to go about testing whether this is the case. Any guidance would be appreciated.

    Does anyone have any ideas about why my code might not be working? Or suggestions for potential fixes? Any advice is appreciated.

    Be the first to reply!

    Leave a Reply