Search code examples
javascriptqualtrics

Adding the percentage symbol before the index in a slider block in a Qualtrics survey?


I want to add the "%" before indexes in a slider question in a Qualtrics survey. By default when I set up a slider question Qualtrics adds "10", "20" and so on in the top of the table, I want to add before every number a percentage symbol. I guess I have to use the javascript editor, but I don't know how to do it.


Solution

  • Add this javascript to your question:

    Qualtrics.SurveyEngine.addOnload(function() {
        var qid = this.questionId;
        var ticks = $(qid).select('span.TickContainer');
        for(var i=0; i<ticks.length; i++) {
            var labels = ticks[i].select('span');
            for(var j=0; j<labels.length; j++) {
                var label = labels[j].innerHTML.trim();
                labels[j].innerHTML = " %" + label + " ";
            }
        }   
    });
    

    P.S. Percent signs usually go after the number, not before. To change to after, change one line:

    labels[j].innerHTML = " " + label + "% ";