Qualtrics - A timer that continues on multiple pages within a block | XM Community
Skip to main content

Hello Qualtrics Community,
In my survey, participants are asked to solve a series of anagrams. However, they only have 12 minutes (720 seconds). In a block, there are 10 anagrams. Each page has an anagram.
I want the timer to be displayed for each page, but I don't want it to refresh. Below is code I tried from this source: https://www.qualtrics.com/community/discussion/7656/how-to-implement-a-time-limit-at-the-block-level-plus-auto-advancing
{
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 = "Time Remaining: 00:10";

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';
display[text] = minutes + ":" + seconds;

if (--timer < 0) {
clearInterval(myTimer);
timeOver();
}
}, 1000);
}
var timerSeconds = parseInt("${e://Field/timeRemaining}");
display = document.querySelector('#time');
startTimer(timerSeconds, display);
var timeOver = function() {
document.getElementById("timer_1").innerHTML = "Time is up.";
x = 1;
var bgColor = setInterval(change, 1000);
$('NextButton').click();
}
});

Note: The embedded data field, timeRemaining was set before the block of questions I wanted the timer to be displayed.
The problem is that the timer displays, but results in NaN:NaN. I'm unsure how to get rid of this problem. As well, a display logic of ("if timeRemaining is greater than 0") should be added on every question except the first and I don't know how to do this. 
Any help is appreciated! Thanks!

Be the first to reply!

Leave a Reply