I need to implement display logic (not using the Qualtrics GUI) using Javascript in a "Multiple Choice" question in the "Dropdown" format, with that logic selectively hiding a subset of potential choices based on the value of an Embedded variable.
Survey flow:
- Question 1 (name=QR~QID1): display all numbers 1 through 5; choose a number.
- Create embedded variable (name=emd_threshold) equaling the choice from Question 1
- Question 2 (name=QR~QID2): display only the numbers 1 through 5 that are less than or equal to the choice from Question 1; choose a number.
Example: if "3" was chosen in Question 1, then only "1, 2, 3" would be shown in Question 2.
Below is code that successfully works when the second question is a "List" format, but I cannot determine how to change it to accommodate a "Dropdown" format.
Qualtrics.SurveyEngine.addOnload(function()
{
var threshold = parseInt("${e://Field/embd_threshold}");
for (let i = 1; i <= 5; i++) {
var choiceoption = "QR~QID2~" + i
if (i > threshold) {
$(choiceoption).up().hide();
}
}
});
Note: I need to Use Javascript here because the real application of this problem involves choice options in the hundreds, for which manual use of Qualtrics' GUI to set display logic for every possible choice and condition is impractical.