How to make this type of timer not visible to participants? | XM Community
Skip to main content

I have a timer stretching across pages that times out after 3 minutes. I have several blocks with this type of timer. I would like the timer not to be visible on the pages to participants as it is counting down. What do I need to change or remove in my code (below) to achieve 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: 03: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; 
   Qualtrics.SurveyEngine.setEmbeddedData('timeRemaining', timer);
if (--timer < 0) {
   clearInterval(myTimer); 
   timeOver(); 
  } 
 }, 1000); 
 } 
 var timerSeconds = 180, 
 display = document.querySelector('#time'); 
 startTimer(timerSeconds, display); 
 var timeOver = function() { 
   $('NextButton').click();
 document.getElementById("timer_1").innerHTML = ""; 
 x = 1; 
 var bgColor = setInterval(change, 1000); 
 } 

});

Qualtrics.SurveyEngine.addOnReady(function()
{
});

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

});

Be the first to reply!

Leave a Reply