What I need to do is loop through all of the courses that are populated in the second dropdown (not just selected courses, all courses) in order to present a question for each course. For example, in the below screenshot, the user would click next and then the survey would loop and ask questions about World Literature, American Literature, and English. When answers have been given for each course the survey is complete.
!
I suspected it was an issue with Qualtrics being unable to loop over a specific Drill Down dropdown, so I have attempted to pipe all courses for a chosen instructor to a separate question (see code below), then loop over that. This doesn't work as Qualtrics doesn't seem to be able to loop over a dynamically generated dropdown list. Also, manually adding display logic through the interface isn't an option because there are over 200 instructors, each with multiple courses. Any ideas?
Thank you!
Qualtrics.SurveyEngine.addOnload(function() {
var ddl1 = document.getElementById("QR~QID1~1"); //Instructor
var ddl2 = document.getElementById("QR~QID1~2"); //Courses
var ddl3 = document.getElementById("QR~QID2"); // Separate dropdown with results from Courses Drill Down
//jQuery("#"+this.questionId).hide();
// When user selects Instructor dropdown
ddl1.onchange = function(element) {
if (ddl1.options[ddl1.selectedIndex].text !== '') {
// Load array with courses for selected instructor
var ddl2Array = new Array();
for (i = 0; i < ddl2.options.length; i++) {
ddl2Array[i] = ddl2.options[i].text;
}
console.log(ddl2Array);
//Clear all previous items from ddl3
ddl3.options.length = 0;
// Populate ddl3 with instructor specific courses
for (var i = 1; i < ddl2Array.length; i++) {
var opt = document.createElement('option');
opt.innerHTML = ddl2Array[i];
opt.value = ddl2Array[i];
ddl3.appendChild(opt);
}
}
}
});
I stumbled across this while searching for an answer to my own similar issue. Unfortunately, I'm not proficient in Javascript, but I'm hoping that I can take this template and tweak it to fit my needs.
TomG In jdn0002 's example above, where does that javascript code actually go? For my form, I need to display spreadsheet-stored addresses for all results in a drill down question (similar to how he needed to follow up on all the courses associated with a given teacher). Does the Javascript code go in the addOnload section of the drilldown question itself, or for the following multiple choice multiple answer question? I'm guessing the latter?
https://community.qualtrics.com/XMcommunity/discussion/comment/40028#Comment_40028It could go in either question, but I would add it to the first since that is where the element your event handler will be attached to.
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.