Hi Qualtrics experts,
I am programming a survey which relies on a question which uses a keypress event, and have encountered a problem where custom code that enables a keypress response appears to 'carry over' to subsequent questions.
The goal of my survey is to create a task where respondents choose between one of two pictures that appear on the right and left sides of the screen. To accomplish this, I have created a binary multiple choice question with one response option referring to the left side of the screen, and a second response option referring to the right side of the screen. Then, using custom javascript code, I have mapped in left/right key presses to replace the manual response for that question, and hidden the question description and response options so subjects have to use the key presses to make their responses. I've also hidden the Next Button. This question works perfectly.
The problem is in the subsequent questions: respondents should not be able to advance through the subsequent questions in the block, as they are programmed using the timer function so that they can only auto-submit after X seconds have passed. I've done this by setting the "enable submit after" parameter equal to the "auto advance after" parameter. However, I've found that those subsequent questions still respond to the keypress events, despite the timer settings. After some further testing, I've found that when I remove the custom javascript pertaining to the keypress event from the first question that the timer works again: respondents cannot advance until the auto advance time threshold has been reached.
So, my question is: Is there any way I can disable the keypress event after that first question to prevent this auto advancing? Below is the custom javascript I have included for the first question. Please let me know if anything about my question is unclear, or if more information is needed, and thank you for your time and help.
// Hide the question description and response options so subjects have to use the key presses
Qualtrics.SurveyEngine.addOnload(function() {
jQuery("#"+this.questionId).hide();
});
// Map in the left and right key presses to respond
Qualtrics.SurveyEngine.addOnload(function() {
var qid = this.questionId;
document.onkeydown = function(event) {
console.log('keydown',event);
if (event.which == 37) {
event.preventDefault();
Qualtrics.SurveyEngine.registry[qid].setChoiceValue(1, true);
jQuery('#NextButton').click();
} else if (event.which == 39) {
event.preventDefault();
Qualtrics.SurveyEngine.registry[qid].setChoiceValue(2, true);
jQuery('#NextButton').click();
}
}
});
// Hide the next button
Qualtrics.SurveyEngine.addOnReady(function(){
this.hideNextButton();
});
Best wishes,
Thomas
How to disable a keypress event?
Best answer by rondev
In the onunload function try the below code:
document.onkeydown = function(event) {}
Sign up
Already have an account? Login
Welcome! To join the Qualtrics Experience Community, log in with your existing Qualtrics credentials below.
Confirm your username, share a bit about yourself, Once your account has been approved by our admins then you're ready to explore and connect .
Free trial account? No problem. Log in with your trial credentials to join.
No free trial account? No problem! Register here
Already a member? Hi and welcome back! We're glad you're here 🙂
You will see the Qualtrics login page briefly before being taken to the Experience Community
Login with Qualtrics
Welcome! To join the Qualtrics Experience Community, log in with your existing Qualtrics credentials below.
Confirm your username, share a bit about yourself, Once your account has been approved by our admins then you're ready to explore and connect .
Free trial account? No problem. Log in with your trial credentials to join. No free trial account? No problem! Register here
Already a member? Hi and welcome back! We're glad you're here 🙂
You will see the Qualtrics login page briefly before being taken to the Experience Community
Login to the Community
Welcome! To join the Qualtrics Experience Community, log in with your existing Qualtrics credentials below.
Confirm your username, share a bit about yourself, Once your account has been approved by our admins then you're ready to explore and connect .
Free trial account? No problem. Log in with your trial credentials to join.
No free trial account? No problem! Register here
Already a member? Hi and welcome back! We're glad you're here 🙂
You will see the Qualtrics login page briefly before being taken to the Experience Community
Login with Qualtrics
Welcome! To join the Qualtrics Experience Community, log in with your existing Qualtrics credentials below.
Confirm your username, share a bit about yourself, Once your account has been approved by our admins then you're ready to explore and connect .
Free trial account? No problem. Log in with your trial credentials to join. No free trial account? No problem! Register here
Already a member? Hi and welcome back! We're glad you're here 🙂
You will see the Qualtrics login page briefly before being taken to the Experience Community
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.
