Log reaction time of key press + auto-advance | XM Community
Solved

Log reaction time of key press + auto-advance

  • 25 May 2018
  • 4 replies
  • 249 views

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
icon

Best answer by LaurenK 9 July 2018, 23:21

View original

4 replies

Userlevel 7
Badge +13
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!
Hi Lauren,

Thanks for your reply! I actually realized yesterday morning that it was working just fine outside the preview mode and was meaning to add this here (just after I was done swearing and wishing I had realized this six weeks ago...). The code indeed works perfectly fine.

Best,
Theresa

Hi there!
I also added this code to my qualtrics for a couple of questions. It works fine when you use the buttons on the computer, but there is no option or possibility to use this on a smartphone or tablet. Do you need to get a seperate code for this. Or is the use of java script only for uses of a desktop.

Best,
Caglar

Hello,
I'm looking to do the same thing, but I am a newbie to Javascript and I am unsure of what this code is composed of. What parts of the code are adapted to your survey e.g. what does the 'choiceID = 1' line refer to the response in your survey (which is '1') that you are measuring? So basically I mean, which parts of the code do I need to change to adapt the code to another survey?
Also, to measure the time of the response per multiple choice question, do I need to set Embedded Data? And how many variables, do I need an Embedded Data variable for each multiple choice question I want to record the time for and name them separately?

Thank you for your help, it is very appreciated!!

Leave a Reply