0 votes
in SoSci Survey (English) by s207574 (120 points)

How can I modify the below js code for a 45 seconds timer or 1 minute and 20-second timer?

// Display countdown
var date0 = new Date();
var timeout = date0.getTime() + %remain% * 1000;
console.log(timeout);
function updateCountdown() {
  // Calculate time
  var date = new Date();
console.log(date)
  var time = Math.ceil((timeout - date.getTime() - 50) / 1000);  // remaining time in seconds
  // Display time
  var out = document.getElementById("remain");
  if (!out) {
    return;
  }
  while (out.lastChild) {
    out.removeChild(out.lastChild);
  }
  var minutes = Math.floor(time / 60);
  var seconds = String(time - 60 * minutes);
  if (seconds.length < 2) seconds = "0" + seconds;
  var display = String(minutes) + ":" + seconds;
  var displayNode = document.createTextNode(display);
  out.appendChild(displayNode);
}
 
// Hide Next button (optional)
  SoSciTools.submitButtonsHide();
 
// Initialize forwarding
SoSciTools.attachEvent(window, "load", function(evt) {
 
  // Additional timer to update the countdown
  window.setInterval(updateCountdown, 1000);
  updateCountdown();
  // Start timer to forward automatically
  window.setTimeout(goNext, %remain% * 1000);
});

1 Answer

0 votes
by SoSci Survey (330k points)

Not at all ... the time is set in the Placehholder %remain% - and this again is set in the PHP code that embeds the JavaScript element.

Please read Placeholders.

Willkommen im Online-Support von SoSci Survey.

Hier bekommen Sie schnelle und fundierte Antworten von anderen Projektleitern und direkt von SoSci Survey.

→ Eine Frage stellen


Welcome to the SoSci Survey online support.

Simply ask a question to quickly get answers from other professionals, and directly from SoSci Survey.

→ Ask a Question

...