使用 javascript 在 Qualtrics 中设置嵌入数据以用于显示逻辑(需要更新?)

Set embedded data in Qualtrics with javascript for use with display logic (need updates?)

虽然这个问题已经解决了几次 here and here,但随后的 Qualtrics 更新使得继续应用这些解决方案变得困难。

我的 objective:计算包含 2 个问题的答案的文本框的数量,并使用该数字确定第三个问题中显示的内容。在分隔第二个和第三个问题的页面上的文本问题类型中使用的以下 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, it works, but then the user can't move back in the survey because jQuery('#NextButton').click(); returns them to the third question. I've tried wrapping the above code in a substitute NextButton code and moving it to the same page with QID2 as shown 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(同一页面)中的所有内容。

我也尝试过在 addOnReadyaddOnUnload 中放置代码,但无济于事。

我需要的是 1) 对解决方案的更新,该解决方案将问题隐藏在中间页面上,该页面修改了页面上的后退按钮,我的第三个问题将参与者踢出 two 向后翻页,或 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}); 

将调查逻辑设置为依赖 count 就可以了。