Help troubleshooting with reaction time script | XM Community
Skip to main content

Hi there,
I was wondering if anyone could point me in the right direction with the errors in my code. The task is a self-referential encoding task (SRET) in which participants are shown a screen that contains the question 'Describes Me?' or 'Upper Case?' followed by a sequence of 5 negative or 5 positive words. Each word is shown on the screen for 3 seconds and the user must make a decision on whether the word describes them or is upper case depending on the condition. My problems are as follows:

  1. The setTimeout function to keep the page on each word for 3 seconds does not seem to be working. Maybe I've placed it in the wrong place?

  2. The reaction time seems to collect reaction time data for a longer period of time than the stimulus page is shown. For example, UAlive reaction time is 6590 ms when the choice can only be made within 3000ms. I checked this particular page and it was only shown for 3000ms. I wonder if the problem is occurring because some of the information is carrying on to the next page. I created separate embedded data for each word and separate javascript within each page (where one word is shown).

Below are some examples of the stimulus page, the reaction time data, and the script I used for each word:
image.png
image.png

Qualtrics.SurveyEngine.addOnload(function () {
 var startTime = new Date().getTime();
 var that = this;
 Event.observe(document, 'keydown', function keydownCallback(e) {
  var choiceID = null;
  switch (e.keyCode) {
   case 71: // '1' was pressed
    choiceID = 1;
    break;
setTimeout(function() {
jquery('#NextButton').click();
}, 3000);
   case 72: // '2' was pressed
    choiceID = 2;
    break;
setTimeout(function() {
jquery('#NextButton').click();
}, 3000);
  }
  if (choiceID) {
   let rTime =new Date().getTime() - startTime;
   Event.stopObserving(document, 'keydown', keydownCallback);
   that.setChoiceValue(choiceID, true);
   Qualtrics.SurveyEngine.setEmbeddedData('DCEasygoingrTime', rTime);
  }
 });
});

For the second problem, I've noticed across various tasks that usually the response time of the first stimulus is considerably higher than the others. I haven't been able to figure out why this is, but I suggest you always keep your first image as a dummy.
There is a flaw in your code, the settimeout blocks are after break and hence will not get executed. However, based on how you've described that task, the code doesn't seem adequate. Perhaps you have JS at places also.


Hi Ahmed,
Oh, I missed the break line. Thank you for pointing that out! I think you are right in that the setTimeout may not be accurate. Is there something in the keypress syntax that can prevent a keypress from triggering the page to automatically move forward again?
Qualtrics.SurveyEngine.addOnload(function () {
 var startTime = new Date().getTime();
 var that = this;
 Event.observe(document, 'keydown', function keydownCallback(e) {
  var choiceID = null;
  switch (e.keyCode) {
   case 71: // '1' was pressed
    choiceID = 1;
    setTimeout(function() {
jquery('#NextButton').click();
}, 3000);
break;
   case 72: // '2' was pressed
    choiceID = 2;
    setTimeout(function() {
jquery('#NextButton').click();
}, 3000);
break;
  }
  if (choiceID) {
   let rTime =new Date().getTime() - startTime;
   Event.stopObserving(document, 'keydown', keydownCallback);
   that.setChoiceValue(choiceID, true);

Qualtrics.SurveyEngine.setEmbeddedData('DAliverTime', rTime);
  }
 });
});
In terms of the conditions, they are randomized when the user views them. The "U" condition should be faster than the "D" condition (see the letter at the beginning of each RT.


I'm sorry. Can you tell me in detail, the interaction you want the respondent to have.
At present its a little too cluttered for me to understand.
Thanks.


Hi Ahmed,
Apologies, here is the task in detail:

  • In total, the task must last 5.6 minutes where there are 20 unique blocks that are pseudo-randomized.

  • each block contains a condition screen + 5 words.

  • there are 2 conditions: participants are asked if each word describes themselves or if the word is upper case.

  • Words are randomized to appear as either uppercase (e.g. ALIVE) or lowercase (e.g. Alive).

  • Words are also either positively or negatively valenced, e.g. Alive (positive) vs Afraid (negative). Each grouping of 5 words will have the same valence.

  • Altogether, participants should see all conditions, all uppercase/lower case versions of each word, and an equal amount of valenced words

  • I have used branching, embedded data and randomization in the survey flow to ensure participants are seeing all possibilities in a block-randomized order

The issue:
  • As the task must be the same length for everyone, I'd like to code it such that participants can press either "g" for "yes" or "h" for "no" as soon as they see the word. This RT would be captured by the embedded data, e.g. UAliveRTime.

  • However, I do not want participants to move onto the next word if less than 3 seconds have elapsed.

  • Given this, participants should not be able to move on to the next word if "g" or "h" is pressed.

Let me know if you have any specific questions that I have not addressed.


Thanks for that. It quite clear.
What I understand is, irrespective of how fast or slow they are at pressing the button, you want them to move forward after 3 seconds.
I.e. Someone answers in 1 second, the next button is clicked after 2 seconds. If someone takes more than three, the next button is automatically clicked.
If this is the case, here's my suggestion, since each word is on a page, use the builtin auto advance in the timing question.
Now to give them the effect of the answer being accepted. Just hide the question container as soon as you record the choice id.
Add this line just before each break:
that.questionContainer.style.display = "none" ;

Let me know if this helps.


Hi Ahmed,
After some troubleshooting I realized that the "jQuery('#NextButton').click();" from the introductory page (where the page moves forward with the press of a key) was carrying forward to the other words.
I gave your suggestion a try and it seems to work but the options disappear after a keypress. Thank you for your help. I will have to fiddle around with the design to make sure this will work on a larger scale, but you've pointed me in the right direction. I also ended up changing the script slightly per word so I'll test a few variations of the original script out with your suggestion as well:
Qualtrics.SurveyEngine.addOnload(function () {
 let questionTime = 3 // The number of seconds the question is to be displayed for.
 this.hideNextButton();
 var that = this;
 (function(){
  that.clickNextButton();
  console.log('NEXT BUTTON');

 }).delay(questionTime);

 var startTime = new Date().getTime();
 var that = this;
 Event.observe(document, 'keydown', function keydownCallback(e) {
  var choiceID = null;
  switch (e.keyCode) {
  case 71: // '1' was pressed
  choiceID = 1;
  break;
  case 72: // '2' was pressed
  choiceID = 2;
  break;
  }
  if (choiceID) {
   let rTime =new Date().getTime() - startTime;
   Event.stopObserving(document, 'keydown', keydownCallback);
   that.setChoiceValue(choiceID, true);
   Qualtrics.SurveyEngine.setEmbeddedData('UCEasygoingrTime', rTime);
  }
 });
});


Okay. If you just want to hide the question text and not the buttons, then you could use this instead:
that.questionContainer.querySelector(".QuestionText").style.display = "none" ;


Leave a Reply