In my Qualtrics survey one block is a timed task. People can take 1 minute on that block. There are many questions in that block one after the another with page break. People can attempt as many questions as possible in that block in one minute and when the time reaches the limit(1 minute) they should be automatically directed to the next block with out seeing the rest of the questions in that timed block. Also a countdown timer should be shown while attempting the timed block.
I tried using java script, the timer works but the auto progression to the next block is not at all happening. How can I solve this?
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'>01: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';
displayxtext] = minutes + ":" + seconds;
if (--timer < 0) {
clearInterval(myTimer);
timeOver();
}
}, 1000);
}
var timerSeconds = 60;
var embeddedTime = "${e://Field/timeRemaining}";
if (!isNaN(parseInt(embeddedTime))) {
timerSeconds = parseInt(embeddedTime);
}
var display = document.querySelector('#time');
startTimer(timerSeconds, display);
function timeOver() {
document.getElementById("timer_1").innerHTML = "Time is up.";
var x = 1;
var bgColor = setInterval(change, 1000);
// Auto progress to the next block
setTimeout(function () {
document.querySelector('#NextButton').click();
}, 3000); // Change the delay (in milliseconds) as needed
}
function change() {
document.body.style.backgroundColor = (x % 2 === 0) ? "white" : "lightgray";
x++;
}
// Add CSS to make the timer fixed at the top of the screen
header.style.position = "fixed";
header.style.top = "0";
header.style.width = "100%";
header.style.zIndex = "1000";
});
With the above above scripts timer works. what changes should be made for the auto progression to next block?