It used to be possible to setChoiceValue in Qualtr

2019-03-06 06:42发布

It used to be possible to use the setChoiceValue method in Qualtrics to have key-presses trigger the selection of a particular option withing a multiple choice question. In fact one could even see the radio-button being "clicked" as a result of pressing a given key on the keyboard. This is no longer the case, apparently due to recent changes in Qualtrics. (An inspection of the resulting Qualtrics data file reveals that no choice value was set.) One suggested workaround has been to write embedded data that indicates the selected choice, instead of the choice actually being selected by setChoiceValue. However, that workaround does not work in the circumstance where the question is inside a loop-and-merge block with randomly ordered loop elements (since the choice selections need to be matchable, later on, to corresponding elements within the loop). So my question is, is there a way to have javascript simulate the clicking of a radio button, in the Qualtrics question, without relying on the apparently-broken setChoiceValue method?

EDIT 1/30/2018 -- ANSWER TO MY OWN QUESTION (it's here now since someone deleted it after I added it, below). ". . . here's what I've found. The script works fine whether it uses addOnload or addOnReady. But what does happen, sometimes, is that Qualtrics 'question' becomes altered so that the choice identifiers are no longer as expected. Even changing the question to a descriptive text type question, and then changing it back to multiple choice (so as to re-create Qualtrics's default choices), doesn't necessarily fix the problem with the identifiers. Creating a new block and a new question, from scratch, does fix the problem."

Qualtrics.SurveyEngine.addOnload(function()
{
this.hideNextButton();
this.hidePreviousButton();
var that = this;
Event.observe(document, 'keydown', function keydownCallback(e) {
  var choiceID = null;
  switch (e.keyCode) {
    case 74: // 'j' was pressed
      choiceID = 1;
      break;
    case 75: // 'k' was pressed
      choiceID = 2;
      break;
  }

  if (choiceID) {
    Event.stopObserving(document, 'keydown', keydownCallback);
    that.setChoiceValue(choiceID, true);
    that.clickNextButton();
  }
});
});

标签: qualtrics
2条回答
我想做一个坏孩纸
2楼-- · 2019-03-06 06:49

setChoiceValue works just fine. In fact, your script will work just fine if you change addOnload to addOnReady.

The change to Qualtrics has to do with timing and when the buttons are available. With addOnload your script is trying to hide the buttons before they are available which halts the script due a JS error.

查看更多
你好瞎i
3楼-- · 2019-03-06 06:53

Thanks! However, here's what I've found:

The script works fine whether it uses addOnload or addOnReady. But what does happen, sometimes, is that Qualtrics 'question' becomes altered so that the choice identifiers are no longer as expected. Even changing the question to a descriptive text type question, and then changing it back to multiple choice (so as to re-create Qualtrics's default choices), doesn't necessarily fix the problem with the identifiers. Creating a new block and a new question, from scratch, does fix the problem.

查看更多
登录 后发表回答