Reaction time not written back to embedded data

zfrank
zfrank Hong KongCommunity Member Qubie ✭

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!

Best Answers

  • TSAcc
    TSAcc Community Member, XMPN Member, Qualtrics Brand Admin Guru ✭✭
    Accepted Answer

    @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.

  • zfrank
    zfrank Hong KongCommunity Member Qubie ✭
    Accepted Answer

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