我正在尝试使用Drill Down问题设置Qualtrics调查。在第一个下拉列表中,用户选择一个教师,然后第二个下拉列表填充所选教师提供的课程。
我需要做的是循环遍历第二个下拉列表中的所有课程(不仅仅是选定的课程,所有课程),以便为每门课程提供一个问题。当为每门课程提供答案时,调查即告完成。
我怀疑这是Qualtrics无法循环钻取问题的一个问题,所以我试图将选定教师的所有课程管道到一个单独的问题(见下面的代码),然后循环。这不起作用,因为Qualtrics似乎无法循环动态生成的字段。此外,通过界面手动创建显示逻辑不是一种选择,因为有超过200名教师,每个教练都有多个课程。有任何想法吗?
谢谢!
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);
}
}
}
});
<div id="Questions" role="main">
<!-- rivets: if runtime.SeparatorDisplayed -->
<div id="QID1Separator" class="Separator"></div>
<div class="QuestionOuter BorderColor DD QID1" id="QID1" questionid="QID1" posttag="QID1" data-runtime-remove-class-hidden="runtime.Displayed">
<div id="QR~QID1~VALIDATION" class="ValidationError" role="alert" data-runtime-show="runtime.ErrorMsg" data-runtime-html="runtime.ErrorMsg" style="display: none;"></div>
<div id="QR~QID1~SDPVALIDATION" class="ValidationError" role="alert" data-runtime-show="runtime.PDPErrorMsg" data-runtime-html="runtime.PDPErrorMsg" style="display: none;"></div>
<div class="Inner BorderColor DL">
<div class="InnerInner BorderColor">
<fieldset>
<legend>
<div class="QuestionText BorderColor">Click to write the question text</div>
</legend>
<div class="QuestionBody">
<table role="presentation" class="ChoiceStructure" cellpadding="0" cellspacing="0">
<tbody>
<tr class="reg">
<td>
<label for="QR~QID1~1">Instructor</label>
</td>
<td>
<!-- the html binding blows aways the value binding, so do that last-->
<select class="drillDownSelectDropDown QWatchTimer" name="QR~QID1~1" id="QR~QID1~1" data-runtime-select-options="runtime.Choices.1.optionHTML" data-runtime-enabled="runtime.Choices.1.enabled" data-runtime-value="runtime.Choices.1.Value">
<option aria-label="Blank"></option>
<option value="1">Smith</option>
<option value="5">Johnson</option>
<option value="8">Baker</option>
</select>
</td>
</tr>
<tr class="alt">
<td>
<label for="QR~QID1~2">Course</label>
</td>
<td>
<!-- the html binding blows aways the value binding, so do that last-->
<select class="drillDownSelectDropDown QWatchTimer" name="QR~QID1~2" id="QR~QID1~2" data-runtime-select-options="runtime.Choices.2.optionHTML" data-runtime-enabled="runtime.Choices.2.enabled" data-runtime-value="runtime.Choices.2.Value" disabled=""></select>
</td>
</tr>
</tbody>
</table>
</div>
</fieldset>
</div>
</div>
</div>
<!-- rivets: if runtime.SeparatorDisplayed -->
<div id="QID2Separator" class="Separator"></div>
<div class="QuestionOuter BorderColor MC QID2" id="QID2" questionid="QID2" posttag="QID2" data-runtime-remove-class-hidden="runtime.Displayed">
<div id="QR~QID2~VALIDATION" class="ValidationError" role="alert" data-runtime-show="runtime.ErrorMsg" data-runtime-html="runtime.ErrorMsg" style="display: none;"></div>
<div id="QR~QID2~SDPVALIDATION" class="ValidationError" role="alert" data-runtime-show="runtime.PDPErrorMsg" data-runtime-html="runtime.PDPErrorMsg" style="display: none;"></div>
<div class="Inner BorderColor MSB">
<div class="InnerInner BorderColor">
<fieldset>
<legend>
<label class="QuestionText BorderColor" for="QR~QID2">Click to write the question text</label>
</legend>
<div class="QuestionBody">
<div class="offScreen">To select multiple options in a row, click and drag your mouse or hold down Shift when selecting. To select non-sequential options, hold down Control (on a PC) or Command (on a Mac) when clicking. To deselect an option, hold down Control or Command and click on a selected option.</div>
<select role="listbox" aria-multiselectable="true" multiple="" size="10" class="ChoiceStructure QR-QID2 QWatchTimer" name="QR~QID2[]" id="QR~QID2" data-runtime-value="runtime.Selected">
<option role="option" class="Selection" aria-selected="false" value="QR~QID2~1" id="QR~QID2~1" data-runtime-text="runtime.Choices.1.Display">Click to write Choice 1</option>
</select>
<div class="clear zero"></div>
</div>
</fieldset>
</div>
</div>
</div>
</div>