Timer Shows Up Again After Clicking Previous | XM Community
Question

Timer Shows Up Again After Clicking Previous

  • 6 November 2020
  • 0 replies
  • 11 views

Hello community,
I have custom code for a timer. However, when respondents go back to a previous page, another timer shows up and starts from 12:00—I just want one timer to display. If anyone knows how to fix this I would really appreciate that : )
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: 12: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 = 720, 
 display = document.querySelector('#time'); 
 startTimer(timerSeconds, display); 
 var timeOver = function() { 
 document.getElementById("timer_1").innerHTML = "Time is up"; 
$('NextButton').click();
 }  


});

Qualtrics.SurveyEngine.addOnReady(function()
{
/*Place your JavaScript here to run when the page is fully displayed*/

});

Qualtrics.SurveyEngine.addOnUnload(function()
{
/*Place your JavaScript here to run when the page is unloaded*/

});


0 replies

Be the first to reply!

Leave a Reply