Hello,
I have a custom timer running in a looped block of questions. After time expires, the program automatically advances to the next block. The code below works well, but the timer is still visible after time expires and participants have moved to the next block. It shows as Time Remaining 0.00 on all pages after the looped block.
Is there a way to modify the code so that the timer is visible only in the timed block and not subsequent blocks? Thanks for your suggestions !
if("${lm://CurrentLoopNumber}" == "1") {
var header = document.createElement("div");
header.className = "header"
header.id = "header_1";
var timer = document.createElement("div");
timer.className = "timer";
timer.id = "timer_1";
timer.innerHTML = "
header.appendChild(timer);
document.body.insertBefore(header, document.body.firstChild);
function startTimer(duration, display) {
var timer = duration, minutes, seconds;
var myTimer = setInterval(function() {
Qualtrics.SurveyEngine.setEmbeddedData('timeRemaining', timer);
minutes = parseInt(timer / 60, 10)
seconds = parseInt(timer % 60, 10);
minutes = minutes < 10 ? "0" + minutes : minutes;
seconds = seconds < 10 ? "0" + seconds : seconds;
var text = ('innerText' in display)? 'innerText' : 'textContent';
displayatext] = minutes + ":" + seconds;
if (--timer < 0) {
clearInterval(myTimer);
$('NextButton').click();
}
}, 1000);
}
var timerSeconds = parseInt("${e://Field/timeRemaining}");
display = document.querySelector('#time');
startTimer(timerSeconds, display);
}
Page 1 / 1
After the block where the time should not appear, add an embedded data variable - say, "timeFlag" - and set it to 1. Then in your code, add a condition that checks: if timeFlag != 1, only then execute the timer stuff.
Hope that helps.
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.