
Solved
JavaScript for keyboard use with multiple choice question
Hi!
I've tried to come up with the right script for allowing participants to respond to a 2-answer multiple choice question by using the keyboard. I would like to have participants use the keyboard 'J' for answer 'No' and the keyboard 'F' for answer 'Yes'. I've recoded the values of the answers to the question as Yes = 1 and No = 2 (also see attachment image:
!
However it still doesn't work. This is what the script looks like now:
Qualtrics.SurveyEngine.addOnload(function()
{
console.log("test");
jQuery(document).keypress(function(event) {
if(event.which==74){Qualtrics.SurveyEngine.setChoiceValueByRecodeValue(2,true)
}
if(event.which==70){Qualtrics.SurveyEngine.setChoiceValueByRecodeValue(1,true)
}
});
});
Qualtrics.SurveyEngine.addOnReady(function()
{
/*Place your JavaScript here to run when the page is fully displayed*/
});
Qualtrics.SurveyEngine.addOnUnload(function()
{
/*Place your JavaScript here to run when the page is unloaded*/
});
Is this script correct? It seems as if the script is not getting 'started'. Would be really happy to find a solution! Thank you, Paul

Best answer by TJUH_Kai
Qualtrics.SurveyEngine.addOnload(function()
{
console.log("test 4");
this.questionContainer.addEventListener('keydown',function(event) {
console.log("someone typed something");
if (event.isComposing || event.keyCode === 74) {
console.log("no");
}
if (event.isComposing || event.keyCode === 70) {
console.log("yes");
}
});
});
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.