Using 3 KEYSTROKES to Answer Survey in Qualtrics

假装没事ソ 提交于 2019-12-25 04:38:20

问题


I use Jscript to enable Keystrokes in Qualtrics to answer a question.

It works as with 2 options as provided in the example by Qualtrics: https://www.qualtrics.com/university/researchsuite/developer-tools/custom-programming/example-code-snippets/#ExampleJavaScript

I added a third Keystroke option (press q) which is not working: somehow the keystroke for q is registered but neither does it enter the data nor proceed to the next question as is the case when pressing j or k. See code below. Any advise appreciated - thanks!

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 choiceID = null;

  switch (e.keyCode) {
    case 74: // 'j' was pressed
      choiceID = 1;
      break;
    case 75: // 'k' was pressed
      choiceID = 2;
      break;
    case 81: // 'q' was pressed
      choiceID = 5;
      break;
  }

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


});
});

回答1:


I'm not sure exactly what is wrong. A few different things it could be:

1) Your code above has an extra }); at the end. However, Qualtrics wouldn't let you save that, so I'm thinking it is just a typo in your post above.

2) If your choiceID is wrong and you have force response turned on, then it won't advance and you'll get an error message.

3) If you are in JFE preview mode, then you have to first get focus on the form before any keypress will work.

BTW, this won't work on mobile devices.

Here is some cleaned up code that also fixes issue (3):

Qualtrics.SurveyEngine.addOnload(function()
{
    $('Buttons').hide();
    if(window.location.pathname.match(/^\/jfe[0-9]?\/preview/)) {
        $(this.questionId).select('input').first().focus();
    }   
    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;
            case 81: // 'q' was pressed
                choiceID = 5;
                break;
        }

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


来源:https://stackoverflow.com/questions/36322857/using-3-keystrokes-to-answer-survey-in-qualtrics

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