Timing question over multiple pages then skip to a question when time is up | XM Community
Skip to main content
Question

Timing question over multiple pages then skip to a question when time is up


Forum|alt.badge.img+2

I am using the following code to set a timer over multiple pages. It works fine, however I want to add a java function to skip to a specific page when the time is up.

 

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'>02: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() {  
   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 = 120,  
 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);  
 }  

});

4 replies

ArunDubey
QPN Level 8 ●●●●●●●●
Forum|alt.badge.img+41
  • QPN Level 8 ●●●●●●●●
  • 589 replies
  • June 6, 2023

you can hide button through CSS. then apply this

setTimeout(function() {
    this.clickNextButton();
}, 3000);

3000=3 second. you can convert your time into miliseconds and pass that value here. if this.clickNextButton() will not work then use actual JS code “jQuery('.NextButton').trigger('click');” instead of Qualtrics JS API.


Forum|alt.badge.img+2
  • Author
  • Level 2 ●●
  • 7 replies
  • June 6, 2023

Thanks alot, that is really helpful! I am actually trying to implement this https://stackoverflow.com/questions/47317718/how-to-use-automatically-move-respondents-in-qualtrics-with-global-timer-for-blo

 

what would the specific codes and embedded variables look like?


ArunDubey
QPN Level 8 ●●●●●●●●
Forum|alt.badge.img+41
  • QPN Level 8 ●●●●●●●●
  • 589 replies
  • June 6, 2023

try this.

Qualtrics.SurveyEngine.addOnload(function()
{
	/*Place your JavaScript here to run when the page loads*/

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'>02: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() {  
   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,  
 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);  
 } 
var timeX =(parseInt(timerSeconds,10) * 1000)+1000;
setTimeout(function() {
   jQuery('.NextButton').trigger('click');
}, timeX);
});

 


ArunDubey
QPN Level 8 ●●●●●●●●
Forum|alt.badge.img+41
  • QPN Level 8 ●●●●●●●●
  • 589 replies
  • June 6, 2023

just to add, for testing purpose, I replaced the var timerSeconds = 10, please change it again as 120.


Leave a Reply