Custom timer - progress to next block without waiting for response | XM Community
Skip to main content
Hi guys,

I have two questions (i.e., watching a video and writing task) in one block, separated by page breaks. I want to set a time limit on the whole block (e.g. 10 minutes). The countdown timer should be visible to the respondent and not restart after each question. After time is up, participants should be auto-advanced to the next block. I have used the following code from the previous posts (See below) but when participants move to the second task, the next button is still visible to them so they can finish the task before time is up, which is problematic. The participants should have 10 minutes for these two tasks and they should not move to the next task before time is up. I tried to hide the continue button with another Java code for 10 minutes but this did not work either.



I would appreciate if someone can help me with this! Thanks a lot!



Qualtrics.SurveyEngine.addOnload(function()

{

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: <span id='time'>10:00</span>";



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();

}

});
Be the first to reply!

Leave a Reply