Reaction time not written back to embedded data | XM Community
Solved

Reaction time not written back to embedded data


Hi all,
I am struggling with my javascript code, it seems to run fine but when I download the data the embedded data field (in this case 'P1' is empty). I would like the code to record a 'F' key press as 1 and 'J' key press as 2 and then record the RT before submitting the page. I tested it using Qualtrics.SurveyEngine.setEmbeddedData('P1', 'testing') and it records the string but not when I try to record the RT variable.
Qualtrics.SurveyEngine.addOnload(function() {

var starttime = new Date().getTime
this.hideNextButton()

var qobj = this;
jQuery(document).keypress(function(event){
var key = event.key.toUpperCase();
if(key == "J" || key == "F") {
            jQuery(this).trigger("mouseup");
            var endtime = new Date().getTime();
var RT = (endtime - starttime)/1000;

            if (key == "F"){
            qobj.setChoiceValueByRecodeValue(1,true);
            } else {
            qobj.setChoiceValueByRecodeValue(2,true);
            }
        Qualtrics.SurveyEngine.setEmbeddedData('P1', RT);
$('NextButton').click();
}
})
});
Any help is much appreciated!

icon

Best answer by zfrank 23 July 2021, 08:03

View original

2 replies

Userlevel 2
Badge +3

zfrank Your first line of code is missing parentheses. Without the parentheses your startime and RT will return NaN. Changing getTime to getTime(); should fix the problem.

TSAcc Ah I see! Thank you so much for spotting that.

Leave a Reply