Something is Wrong with my JavaScript | XM Community
Skip to main content
Question

Something is Wrong with my JavaScript

  • 30 July 2024
  • 0 replies
  • 28 views

I am trying to code a left and right key stroke and record the response while participants watch a video. It seems the right arrow key is working but the left arrow key sends the video back 5 seconds insted of recording the response. This is the script I am using:

Qualtrics.SurveyEngine.addOnload(function() {
    var qobj = this;
    document.onkeydown = function(event) {
        console.log('keydown',event);
        if (event.key == 'ArrowLeft') {
            event.preventDefault();
            qobj.setChoiceValue(1, true);
            Qualtrics.SurveyEngine.setEmbeddedData('Practice 1 answer', 1);
            qobj.clickNextButton();
        } else if (event.key == 'ArrowRight') {
            event.preventDefault();
            qobj.setChoiceValue(2, true);
            Qualtrics.SurveyEngine.setEmbeddedData('Practice 1 answer', 2);
            qobj.clickNextButton();
        }
    }


});

 

Be the first to reply!

Leave a Reply