I programmed a timer for each question which captures the time people spend on the question. I could not use Qualtrics in built timer because I want people to be able to pause the timer. The data in seconds for each question should be added to an embedded variable called 'response_time'. I have created new embedded variable to record timer data for each question.
Q embedded var
Q1 response_time
Q2 response_time2
Q3 response_time3
The results are forward cumulative, and only the last question has its time data correctly recorded in embeded variable. The result is the following -
response_time = timer value from Q1 + timer value from Q2 + timer value from Q3
response_time2 =timer value from Q2 + timer value from Q3
response_time3 = timer value from Q3
I do not want other response times to be added. I even renamed all common variables to ensure there is no cross referencing. How can I get around it?
I am attaching the code here -
JAVA
Qualtrics.SurveyEngine.addOnload(function()
{
var h2 = document.getElementsByTagName('h2')[0],
start = document.getElementById('start2'),
stop = document.getElementById('stop2'),
clear = document.getElementById('clear'),
timerecord = document.getElementById('timerecord2'),
seconds_2 = 0, minutes_2 = 0, hours_2 = 0,
t;
function add2() {
seconds_2++;
if (seconds_2 >= 60) {
seconds_2 = 0;
minutes_2++;
if (minutes_2 >= 60) {
minutes_2 = 0;
hours_2++;
}
}
h2.textContent = (hours_2 ? (hours_2 > 9 ? hours_2 : "0" + hours_2) : "00") + ":" + (minutes_2 ? (minutes_2 > 9 ? minutes_2 : "0" + minutes_2) : "00") + ":" + (seconds_2 > 9 ? seconds_2 : "0" + seconds_2);
timer2();
}
function timer2() {
t = setTimeout(add2, 1000);
var time2 = seconds_2 + minutes_2*60 + hours_2*3600;
Qualtrics.SurveyEngine.setEmbeddedData( 'response_time2', time2);
jQuery("#infodiv2").hide();
jQuery("#start2").hide();
jQuery("#stop2").show();
//jQuery(timerecord).hide();
}
timer2();
/* Start button */
start.onclick = timer2;
/* Stop button */
stop.onclick = function() {
clearTimeout(t);
jQuery("#infodiv2").show();
jQuery("#stop2").hide();
jQuery("#start2").show();
//jQuery(timerecord).hide();
}
/* Clear button */
clear.onclick = function() {
h2.textContent = "00:00:00";
seconds_2 = 0; minutes_2 = 0; hours_2 = 0;
}
});
HTML
Any help is appreciated!! Thanks