Answering questions with keystrokes in Qualtrics javascript

196 views Asked by At

I'm trying to allow for participants to press one of two buttons to answer a two-option question in my Qualtrics survey, and automatically advance to the next page. I'm using the code below. When I try it out, pressing "j" and "k" work for answering the question and advancing to the next page. But the "Next" button still shows on the page. How do I hide the "Next" button? That part of the code doesn't seem to be working.

I want the page to look like this: https://survey.qualtrics.com/jfe/form/SV_0xhfEoQxMvScnYM?SVID= with no "Next" button. Thank you for your help!

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();
  }
});
});
2

There are 2 answers

2
Anthony Rivas On

Replace

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

with

$('NextButton').hide();
$('PreviousButton').hide();
0
G.Z.P On

The page you show has not change its URL address, so I think this basically is a single page application. If you want to operate in two page, you should add a parameter after each page, and next page get his URL'param to oprate,