Solved
Log reaction time of key press + auto-advance
Hi there,
I am trying to set up a multiple choice question with two answer options that does the following things:
1. The time it takes the respondent to make a decision is recorded (I do this by adding a timing question)
2. Instead of using the mouse, I want respondents to use either of two designated keys on the keyboard to log their response
3. The respondent should then advance automatically to the next question/block once they made a decision
I found some code that should do exactly that (see below). However - for some reason I don't understand - it does the following things instead:
1. I need to select an answer with the mouse. Thus, pressing j or k in order to select an answer doesn't do the trick.
2. However, once I selected an answer with the mouse and I press either j or k, I do advance to the next question.
What could be going wrong here and how can I fix it? Thanks so much in advance!
Theresa
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();
}
});
});
Source: https://sites.google.com/site/complexcognitionbgsu/data-collection-software/qualtricsadvanced
Best answer by LaurenK
Hi @theresa! Are you testing your Javascript using the Anonymous Link, instead of the preview link? If you are using the preview link, you'll have to click on the survey with your mouse before the key press will work. It sounds like others who have used that code may have experienced similar issues. To ensure those ChoiceID's match up with the code you provided, I would recommend creating a new question from scratch so the IDs are in order!
View originalLeave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.