Search code examples
javascriptsurveyqualtrics

Record the order that different options are chosen on Qualtrics


I am using Qualtrics for a survey and have been trying to find a way to record the order that different options are chosen for checkbox questions. For example, if there are 6 options in total for a checkbox question, and a participant clicks the 4th one then the 2nd one, I will be able to obtain a string "4-2".

In addition, I would also like to obtain a metric to see if an option is selected or unselected multiple times. I think this can be backed out by how many times an option is clicked. So for example, "4-2-4" will tell me that a person first selects option 4 then deselects it.

The closest code I can come up with is the following:

Qualtrics.SurveyEngine.addOnload(function (){

    this.questionclick = function(event,element){        
        //for a single answer multiple choice question, the element type will be radio
        if (element.type == 'checkbox')        
        {            
            var choiceNum = "${e://Field/choiceOrder}"+ "|" + element.id.split('~')[2];    
            Qualtrics.SurveyEngine.setEmbeddedData('choiceOrder', choiceNum);
        }    
    }
});

However it only records the last click (choice).

Is there a way to change the code so that it can record all the clicks (choices)? Thanks!


Solution

  • ${e://Field/choiceOrder} gets resolved on the server before sending the page to the browser. So the value will never change. Try this instead:

    Qualtrics.SurveyEngine.addOnload(function (){
        var choiceOrder = "${e://Field/choiceOrder}";
        this.questionclick = function(event,element){        
            //for a single answer multiple choice question, the element type will be radio
            if (element.type == 'checkbox')        
            {            
                choiceOrder = choiceOrder + "|" + element.id.split('~')[2];    
                Qualtrics.SurveyEngine.setEmbeddedData('choiceOrder', choiceOrder);
            }    
        }
    });