Skip to content

Instantly share code, notes, and snippets.

@rpowers
Created May 6, 2016 11:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rpowers/979cc7995b461932738a4143e9d2c5a4 to your computer and use it in GitHub Desktop.
Save rpowers/979cc7995b461932738a4143e9d2c5a4 to your computer and use it in GitHub Desktop.
Randomly flip/rotate response option order in Qualtrics
// Set an embedded data element called "response_order" in survey flow to randomly have value of "reversed" half the time
// Add the following JavaScript to the questions for which you want to flip the ordering (see here: https://www.qualtrics.com/support/survey-platform/edit-survey/question-options/add-javascript/).
// This is a (very) minor variation on: http://stackoverflow.com/a/30766022
// It allows all response scales to increase/decrease in the same direction for a given respondent, but avoids response order bias.
Qualtrics.SurveyEngine.addOnload(function() {
var r_order = "${e://Field/response_order}"
if(r_order == "reversed") {
var qid = this.questionId;
var choices = $(qid).select('li.Selection');
var lastChoice = choices.last();
for(i=0;i<choices.length-1;i++) {
$(lastChoice).insert({
after: choices[i]
});
}
}
});
@rpowers
Copy link
Author

rpowers commented May 6, 2016

A similar process can be used to flip the order of answer choices of matrix style questions:

Qualtrics.SurveyEngine.addOnload(function() {
    var r_order = "${e://Field/response_order}"
    if(r_order == "reversed") {
        var qid = this.questionId;
        var headers = $(qid).select('tr.Answers > th');
        var lastHeader = headers.last();
        for(i=0;i<headers.length-1;i++) {
            $(lastHeader).insert({
                after: headers[i]
            });
        }
        var choiceRows = $(qid).select('tr.ChoiceRow');
        for(i=0;i<choiceRows.length;i++) {
            var choices = $(choiceRows[i]).select("td:not(.BorderColor)");
            var lastChoice = choices.last();
            for(c=0;c<choices.length-1;c++) {
                $(lastChoice).insert({
                   after: choices[c]
                });
            }
        }
    }
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment