Integrating keyboard use with answer randomization in Qualtrics

女生的网名这么多〃 提交于 2019-12-12 05:26:13

问题


I'm using qualtrics to present a user with two choices, one on the left and one on the right. I'd like to have them use the keyboard arrow keys to make a selection and I currently have code to let them do this using the following:

Qualtrics.SurveyEngine.addOnload(function()
{
    /*Place Your Javascript Below This Line*/

this.hideNextButton();
this.hidePreviousButton();

var that = this;

Event.observe(document, 'keydown', function keydownCallback(e) {
    var qid = this.questionId;
    var order = $("QR~"+qid+"~DisplayOrder").value.split("|");
    var left = order[0];
    var right = order[1];


  switch (e.keyCode) {
    case 37: // 'L' was pressed
      choiceID = left
      break;
    case 39: // 'R' was pressed
      choiceID = right
      break;
  }

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

    });

If the answers are randomized and questions are not reversed it works fine. If the answers are reversed it will select the option on the right when the left arrow key is pressed, and vice versa. I suspect I need some way to set the choice ID to the ID of what is actually presented, or completely change the third and sixth lines, but some of the more promising functions in the API don't seem to pan out. Suggestions?


回答1:


You can get the display order of the randomized choices, then assign values to left and right (I'm assuming this is a simple multiple choice question):

var qid = this.questionId;
var order = $("QR~"+qid+"~DisplayOrder").value.split("|");
var left = order[0];
var right = order[1];

Then, in your code:

switch (e.keyCode) {
    case 37: // 'L arrow' was pressed
        choiceID = left
        break;
    case 39: // 'R arrow' was pressed
        choiceID = right
        break;
}


来源:https://stackoverflow.com/questions/28976286/integrating-keyboard-use-with-answer-randomization-in-qualtrics

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!