Hello everyone,
I commissioned a java developer to build the code below to record participants' reaction times, meaning how long it takes from the offset of a stimulus on screen to participant pressing a response key. Unfortunately the code does not work, as half of the times it exports the reaction times as 000, like the example below:
correct export: 1131,220,135,330,74,1697,1151,676,668,303,373
wrong export: 127,167,160,157,110,000,000,000,000,000,000
Below I share the full code. Any idea of why this might be the case will be really appreciated.
var t;
Qualtrics.SurveyEngine.addOnload(function() {
/*Place your JavaScript here to run when the page loads*/
jQuery("#Buttons").hide();
});
Qualtrics.SurveyEngine.addOnReady(function() {
/*Place your JavaScript here to run when the page is fully displayed*/
var qid = this.questionId;
jQuery("#"+qid+" .QuestionText").css("padding-bottom","0px");
jQuery("#"+qid+" .ChoiceStructure").css("border-spacing","3px 0px");
var align = "${e://Field/alignment}";
var time = parseInt("${e://Field/time}");
var curri = 0;
console.log(time)
jQuery("#Buttons").hide();
this.hideNextButton();
this.hidePreviousButton();
jQuery("#" + qid + " .QuestionBody").css("pointer-events", "none");
var that = this;
var c = 0;
var currchoice= "";
var timer_is_on = 0;
function timedCount() {
c = c + 1;
t = setTimeout(timedCount, 1);
}
function startCount() {
c = 0;
if (!timer_is_on) {
timer_is_on = 1;
timedCount();
}
}
function stopCount() {
clearTimeout(t);
timer_is_on = 0;
}
jQuery(document).on('keydown', function(event) {
if (!timer_is_on) {
return;
}
var key = event.key.toUpperCase();
if (align == "left") {
if (key == "A") {
jQuery('input[type="checkbox"]:eq(1)').prop('checked', true); //No
currchoice = "0";
jQuery("#NextButton").click();
} else if (key == "L") {
jQuery('input[type="checkbox"]:eq(0)').prop('checked', true); //YES
currchoice = "1";
jQuery("#NextButton").click();
}
} else {
if (key == "A") {
jQuery('input[type="checkbox"]:eq(0)').prop('checked', true); //YES
currchoice = "1";
jQuery("#NextButton").click();
} else if (key == "L") {
jQuery('input[type="checkbox"]:eq(1)').prop('checked', true); //NO
currchoice = "0";
jQuery("#NextButton").click();
}
}
console.log(currchoice);
});
var targetid = "imgr";
if (align == "left") {
var el = jQuery('#' + qid + ' .LabelContainer:eq(0)').detach();
jQuery("#" + qid + " .ChoiceStructure tbody tr").append(el);
jQuery(".no").text('A');
jQuery(".yes").text('L');
targetid = "imgl";
jQuery("#imgr").attr('src', "${lm://Field/1}");
jQuery("#"+targetid).on('load', function() {
if(curri==0)return;
setTimeout(function() {
curri=0;
jQuery("#"+targetid).show().attr("src", "https://cardiffmet.eu.qualtrics.com/ControlPanel/Graphic.php?IM=IM_0iyWXtOyRB7QZqR");
jQuery("#" + qid + " .QuestionBody").show();
startCount();
}, time);
});
curri = 0;
jQuery("#" + targetid).attr("src", "https://cardiffmet.eu.qualtrics.com/ControlPanel/Graphic.php?IM=IM_87CytKMbs8ODCbX");
setTimeout(function() {
curri = 1;
jQuery("#" + targetid).attr('src', "${lm://Field/2}");
}, 1000);
} else {
jQuery("#imgl").attr('src', "${lm://Field/1}");
jQuery("#"+targetid).on('load', function() {
//herererere
if(curri==0)return;
setTimeout(function() {
curri=0;
jQuery("#"+targetid).show().attr("src", "https://cardiffmet.eu.qualtrics.com/ControlPanel/Graphic.php?IM=IM_0iyWXtOyRB7QZqR");
jQuery("#" + qid + " .QuestionBody").show();
startCount();
}, time);
});
curri = 0;
jQuery("#" + targetid).attr("src", "https://cardiffmet.eu.qualtrics.com/ControlPanel/Graphic.php?IM=IM_87CytKMbs8ODCbX");
setTimeout(function() {
curri = 1;
jQuery("#" + targetid).attr('src', "${lm://Field/2}");
}, 1000);
//jQuery("#imgr").attr('src',"${lm://Field/2}");
}
jQuery("#NextButton").on('click', function() {
var s = "${e://Field/T3BL1_Sequence}";
var arr;
if (s == "") {
arr = [];
} else {
arr = s.split(",");
}
arr.push("${lm://Field/3}");
Qualtrics.SurveyEngine.setEmbeddedData("T3BL1_Sequence", arr.toString());
s = "${e://Field/T3BL1_ReactionTime}";
arr=[];
if (s == "") {
arr = [];
} else {
arr = s.split(",");
}
arr.push(c);
Qualtrics.SurveyEngine.setEmbeddedData("T3BL1_ReactionTime", arr.toString());
s = "${e://Field/T3BL1_Choices}";
arr=[];
if (s == "") {
arr = [];
} else {
arr = s.split(",");
}
arr.push(currchoice);
Qualtrics.SurveyEngine.setEmbeddedData("T3BL1_Choices", arr.toString());
});
});
Qualtrics.SurveyEngine.addOnUnload(function() {
/*Place your JavaScript here to run when the page is unloaded*/
clearTimeout(t);
jQuery(document).off("keydown");
});
Question
Custom code for reaction times not working
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.
