I'm trying to implement javascript to calculate reaction times for a set of randomized questions (within a randomized block) and am having trouble getting the full string of reaction times to appear in the survey's Embedded Data. I've found some really useful code on here and have modified slightly to fit my project. Here's what I have so far:
Qualtrics.SurveyEngine.addOnload(function()
{
var starttime = new Date().getTime();
$('NextButton').hide();
this.questionclick = function(event,element){
if (element.type == 'radio') {
var endtime = new Date().getTime();
var RT = (endtime - starttime)/1000;
var EmData = Qualtrics.SurveyEngine.getEmbeddedData('reactiontime');
var Holder = [];
if (EmData == null){
Holder += "RT1:";
Holder += RT;
Qualtrics.SurveyEngine.setEmbeddedData('reactiontime', Holder);
}
if (EmData != null){
Holder += EmData;
Holder += ", ";
Holder += "RT1:";
Holder += RT;
Qualtrics.SurveyEngine.setEmbeddedData('reactiontime', Holder);
}
$('NextButton').click();
}
}
});
The Holder text (e.g., "RT1") is modified for each question, so question 2 is RT2 and so on.
This DOES produce embedded data that I can view at the end of my survey, and each RT is nicely labelled so that I can tell which question it came from. The problem that I'm having is that I am not reliably getting the RT data for every question -- using a practice set of 9 questions, I am ending up with somewhere between 3-5 RTs in my embedded data (e.g., reactiontime RT4: 3.145, RT7: 3.148, RT9: 3.331, RT6: 2.923). I can't figure out why the remaining questions are not mapping into the embedded data field correctly. Also, note that the questions that DO appear in the embedded data change each time I trial the questions, so it doesn't appear to be an issue with specific questions, but rather the final string of data that's produced.
Does anyone have any suggestions as to how I can correct this so that ALL reaction times appear in my embedded data?
Thanks in advance!
Best answer by bmills
View original