Javascript for Qualtrics to alter choice options

Here is some Javascript code for altering the current question’s multiple-choice options based on the respondent’s answer to a previous multiple-choice question. Specifically, this code considers the response given to a previous question and modifies the current question to remove any answer options that are lower than the previous response. [Note: I hard-coded the number of options as 10. If there are fewer than 10, it will not throw an error.]

This could be used, for example, when Q1 asks the lowest amount ever paid and Q2 asks the highest amount ever paid, with Q1 and Q2 using the same response scale. The code could be used to remove options in Q2 that are lower than the response to Q1. In such a situation, it’s obvious that the answer to Q2 couldn’t be lower than the answer to Q1, so the lower response options can be removed, thereby making the questionnaire shorter and simpler.

Qualtrics.SurveyEngine.addOnload(function()
{

/* In the next line, QID43 must be edited to refer to the specific previous question */
var prev_ans = "${q://QID43/SelectedChoicesRecode}";
var i;
for (i = 1; i < 10; i++) {
if (i < prev_ans) {
$(this.questionId).getElementsByClassName("ChoiceStructure")[0].getElementsByTagName("li")[i-1].style.display = "none";
}
}

});

 
– Eric DeRosia