Make count of response question apply to each slider of a matrix question and non-matrix question | XM Community
Skip to main content

I have made the following code to count the number of times 0, 5, or 10 are selected in questions throughout my survey on Qualtrics. I place this code in each question:

 

```

Qualtrics.SurveyEngine.addOnload(function() {
    var isCorrect10 = 10;
    var currentCounter10 = Qualtrics.SurveyEngine.getEmbeddedData("Counter10");
    
    if (!currentCounter10) {
        currentCounter10 = 0;
    }
    
    var isCorrect0 = 0;
    var currentCounter0 = Qualtrics.SurveyEngine.getEmbeddedData("Counter0");
    
    if (!currentCounter0) {
        currentCounter0 = 0;
    }
    
    var isCorrect5 = 5;
    var currentCounter5 = Qualtrics.SurveyEngine.getEmbeddedData("Counter5");
    
    if (!currentCounter5) {
        currentCounter5 = 5;
    }
    

    // If it's selected, increment 
    if (isCorrect10) {
        currentCounter10++;
        Qualtrics.SurveyEngine.setEmbeddedData("Counter10",currentCounter10.toString());
    }
    
    if (isCorrect0) {
        currentCounter0++;
        Qualtrics.SurveyEngine.setEmbeddedData("Counter0",currentCounter0.toString());
    }
    
    if (isCorrect5) {
        currentCounter5++;
        Qualtrics.SurveyEngine.setEmbeddedData("Counter5",currentCounter5.toString());
    }
    

});

 

```

For this I initialize embedded data for Counter0, Counter5 and Counter10, all at 0.

This works perfectly for questions where it is just one singluar slider. However, I want this to work for matrix questions were there are multiple questions. I want to count every appearance of count in each slider of a matrix, and also be compatible with the non-matrix questions. So each count (0,5,10) should be the total of all selections across all questions. How can I modify the javascript accoridngly

Be the first to reply!

Leave a Reply