Creating skip logic based on if space bar is pressed | XM Community
Question

Creating skip logic based on if space bar is pressed

  • 17 January 2021
  • 2 replies
  • 26 views

Badge

Hello, I would like to create a task in which stimuli are presented to participants in the following way: each stimulus will auto-advance after 0.2 seconds to the following stimulus, unless the participant presses the space bar. If they press the space bar, I would like to make it so that it skips to the next block (or the end of the current block). I have used javascript so that space bar functions as the next button. Is there a way for me to create skip logic (maybe with another java script code) so that if the participant presses the space bar it skips to a different question instead of autoadvancing to the question which immediately follows. This is the code I'm currently using for space go to the next question: Qualtrics.SurveyEngine.addOnReady(function() {
  $('NextButton').hide();
  if($('PreviousButton')) $('PreviousButton').hide();
  var evt = document.on('keydown', function(e) {
    if (e.which == 32) { //space bar pressed
      evt.stop();
      $('NextButton').click();
    }  
  });
});
Is there a way I can change this so that instead of to the next question it goes to a specific question later in the survey?
Thank you! 


2 replies

Userlevel 7
Badge +21

You could look at creating a dummy question on the page, which remains hidden. Which could be used to drive the skip logic.
Along with clicking the next button, the spacebar could also be used to assign some answer to this question, which triggers the skip logic.
Alternatively, you could use the space bar to set the value of some embedded data variable, which can be used from the questions on the upcoming pages. If you are within the same block, you can use display logic, if there are multiple blocks, you can use skip logic.

Badge

Thank you for your response! Do you know what the javascript would look like for either of the options you suggested? I'm new to javascript so don't know how to edit the code properly to suit my needs.

Leave a Reply