Reaction time not written back to embedded data

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
	var qobj = this;
	var key = event.key.toUpperCase();
	if(key == "J" || key == "F") {
                var endtime = new Date().getTime();
                var RT = (endtime - starttime)/1000;

                if (key == "F"){
                } else {
            Qualtrics.SurveyEngine.setEmbeddedData('P1', RT);

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.