Reaction time not written back to embedded data | XM Community
Skip to main content

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!

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