虽然这个问题已被解决过几次here和 here ,后续的 Qualtrics 更新使得继续应用这些解决方案变得困难。
我的目标:计算包含两个问题的答案的文本框的数量,并使用该数字确定第三个问题中显示的内容。在分隔第二个问题和第三个问题的页面上的文本问题类型中使用以下 JavaScript 代码效果很好:
Qualtrics.SurveyEngine.addOnload(function()
{
//Count up the number of text boxes with anything in them
var count = 0;
if('${q://QID1/ChoiceTextEntryValue/1}') count++;
if('${q://QID1/ChoiceTextEntryValue/2}') count++;
//etc...
if('${q://QID2/ChoiceTextEntryValue/1}') count++;
if('${q://QID2/ChoiceTextEntryValue/2}') count++;
//etc...
//Set count as embedded data (added to survey flow earlier)
Qualtrics.SurveyEngine.setEmbeddedData('count', count);
};
问题是我的第二个问题和第三个问题之间有一个无用的页面。如果我使用显示逻辑来隐藏此代码中的干预问题,则该代码不会执行。如果我使用 javascript 隐藏问题并自动移至下一页,如所述 here ,它有效,但用户无法在调查中返回,因为 jQuery('#NextButton').click();
将他们返回到第三个问题。我尝试将上述代码包装在替代 NextButton
代码中,并将其移动到与 QID2 相同的页面,如图 here 所示。至少有一个我能弄清楚的更新:
this.hideNextButton ();
$('NextButton').insert({
before: "<input id=\"checkButton\" type=\"button\" value=\" -> \" title=\" -> \">"
});
$('checkButton').onclick = function() {
//Previous count and set code here
$('NextButton').click();
};
这适用于计算 QID1(位于上一页)中的所有内容,但不能捕获 QID2(同一页面)中的所有内容。
我还尝试过将代码放入 addOnReady
和 addOnUnload
中,但无济于事。
我需要的是 1) 更新解决方案,将问题隐藏在中间页面上,该解决方案使用我的第三个问题修改页面上的“后退”按钮,将参与者踢回两页,或 2) 更新替代按钮解决方案,该解决方案将从同一页面上的问题中获取计数。
最佳答案
根据@T.Gibbons 给出的提示,我能够让事情正常进行。
将 count1
作为嵌入数据包含在调查流程中后,第一个问题的代码:
//Count up the number of text boxes with anything in them
var qid = this.questionId; //Pull question id
//Focus on a text box to force listener to fire; ensures downstream logic will work regardless of participant behavior
document.getElementById('QR~'+qid+'~1').focus();
var quest = document.getElementById(qid); //Set up listener
quest.addEventListener('blur', function() {
var count1 = 0;
if(document.getElementById('QR~'+qid+'~1').value) count1++;
if(document.getElementById('QR~'+qid+'~2').value) count1++;
//and so on...
//Set count1 as embedded data
Qualtrics.SurveyEngine.setEmbeddedData('count1', count1);
}, {capture: true});
在调查流程中包含 count
后,第二个问题的代码:
//Count up the number of text boxes with anything in them, add to prior question
var qid = this.questionId; //Pull question id
var count1 = Qualtrics.SurveyEngine.getEmbeddedData('count1'); //Pull count1 from previous question
document.getElementById('QR~'+qid+'~1').focus(); //Focus on a text box, force listener to fire
//Set up listener
var quest = document.getElementById(qid);
quest.addEventListener('blur', function() {
var count2 = 0;
if(document.getElementById('QR~'+qid+'~1').value) count2++;
if(document.getElementById('QR~'+qid+'~2').value) count2++;
// and so on...
var count = count1 + count2;
//Set count as embedded data
Qualtrics.SurveyEngine.setEmbeddedData('count', count);
}, {capture: true});
将调查逻辑设置为取决于计数
,这样就可以了。
关于javascript - 使用 javascript 在 Qualtrics 中设置嵌入数据,以便与显示逻辑一起使用(需要更新?),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48818156/