I control a single MC question (yes/no) with arrow keys (this is working so far):
Qualtrics.SurveyEngine.addOnload(function() {
var qid = this.questionId;
jQuery(document).keydown(function(event) {
console.log('keydown', event);
if (event.key == "ArrowLeft") {
event.preventDefault();
Qualtrics.SurveyEngine.registry[qid].setChoiceValueByRecodeValue(1, true);
jQuery('#NextButton').click();
} else if (event.key == "ArrowRight") {
event.preventDefault();
Qualtrics.SurveyEngine.registry[qid].setChoiceValueByRecodeValue(0, true);
jQuery('#NextButton').click();
}
});
});
This script is affecting all questions (not only the one in which I put the code), but I want to limit the key bindings to one specific question only. How can I remove the binding?
Page 1 / 1
You need to turn off the keydown event handler after the left or right arrow keys are pressed using jQuery .off().
Thank you so much, it worked! For more information see https://api.jquery.com/off/
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.