I am using the code below so participants can press a key to respond and then immediately progress to the next page. I want to limit the keys that will register to r, b, g, and y. What do I need to modify in the code I have already so that the page only progresses when one of those keys is pressed?
Qualtrics.SurveyEngine.addOnReady(function() {
var input = jQuery("#"+this.questionId+" input[type=text]");
input.select().focus(); //works on desktop, but not on all mobile browsers
input.keydown(function(e) { if(e.which == 13) jQuery("#NextButton").click(); });
});
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: // 'spacebar' was pressed
choiceID = 1;
break;
}
if (choiceID = 1) {
Event.stopObserving(document, 'keydown', keydownCallback);
that.setChoiceValue(choiceID, true);
that.clickNextButton();
}
});
});
Question
Defining specific keypress to progress
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.
