Timing to first keypress in essay box | XM Community
Skip to main content
Hi,

I'm trying to add a timer to an essay question so that participants are timed until they start typing in the text box. I found some previous discussion asking about this, but they ultimately didn't have a conclusion. Probably some type of event viewer with a keydown and keyup, but I'm not sure how to code it.



Thanks.
If you want to avoid using javascript: all you have to do is add a timing question in the same page as your essay question. The timing question records: first click, last click, page submit and click count. Then, in survey flow you create an embedded variable that will equal: page submit minus first click.



Example: $e{ e://Field/timingTemp1 - e://Field/timingTemp2 }



Where Field/timingTemp1 would be the piped in text for "page submit" and Field/timingTemp2 would be the piped in text for first click. This is assuming that they type on the first click. Otherwise, you'd have to set an embedded variable through javascript that records when they first type.
Thanks! I think I'll probably have to do the latter solution. You wouldn't by chance have any reading I can do on how to properly set that up would you?
To get the total time in seconds after the first key is pressed in text box, use the below code.



Create an embedded data in survey flow before this essay question. Paste the below code in the JS (OnReady) of the essay question



var i = 0;

var isRecording = false;

var s;

jQuery("#"+this.questionId+" .InputText").on('keydown', function(){

if(!isRecording){

isRecording = true;

s = setInterval(function(){ i++;}, 1000);

}

});



jQuery("#NextButton").on('click',function(){

clearInterval(s);

Qualtrics.SurveyEngine.setEmbeddedData("TotalTime", i);

});

Leave a Reply