Dear community,
I have embedded a timer over multiple pages within one block that works perfectly. I also managed to integrate a function that send the participants to the next page. However, I'd actually like the participants to be sent to the next block. So far, I have understood that this is not possible.
To circumvent this issue, I decided that all participants would need to go to the last page within this block to wait for the next button to appear as soon as the timer has reached 0.
This is the code for the timer that I use:
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: 05:00";
header.appendChild(timer);
document.body.insertBefore(header, document.body.firstChild);
function startTimer(duration, display) {
var timer = duration, minutes, seconds;
var myTimer = setInterval(function() {
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 = 10, // This needs to be 1 second shorter than the total time, as it seems to increment 1 late
display = document.querySelector('#time');
startTimer(timerSeconds, display);
var timeOver = function() {
document.getElementById("timer_1").innerHTML = "Time is up.";
x = 1;
Qualtrics.SurveyEngine.setEmbeddedData('timeUp', 1);
Qualtrics.SurveyEngine.setEmbeddedData('timeRemaining', 1);
}
Qualtrics.SurveyEngine.addOnPageSubmit(function() {
Qualtrics.SurveyEngine.setEmbeddedData('timeRemaining',timer);
clearInterval(myTimer);
});
});
Qualtrics.SurveyEngine.addOnReady(function()
{
//$('PreviousButton').hide();
$('PreviousButton').disable();
});
Qualtrics.SurveyEngine.addOnUnload(function()
{
});
I am using the code below to guide the next button.
Qualtrics.SurveyEngine.addOnReady(function() {
jQuery("#NextButton").hide();
});
My line of though would be making the disappearance conditional on the embedded data "timeRemaining", which I have already included in the timeOver function of the timer. I.e. when time is over, the variable should be =1.
How can I make the disappearance conditional now?
I'd be overly grateful for a solution as I have been busting my head on this issue for the past two days.
Best regards
Jennifer
Question
Hiding next button until timer has run out
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.
