0 votes
in SoSci Survey (English) by s098891 (355 points)
edited by s098891

For some items, the countdown appears as it should. For others (although I use the same settings, the next page appears instead of the time.

Sometimes, even though I do not change anything, it works. And then again it doesn't. Could it be that soscisurvey sometimes doesn't work?

1 Answer

0 votes
by SoSci Survey (328k points)

I assume, you are using the PHP and JavaScript codes from the manual? Sounds like you may have an issue with variables used on different pages... Does the code work if you start directly with that page?

Using isset() and registerVariable() may lead to unexpected results. However, without knowing what you did (which codes exactly), it's hard to narrow the problem down.

by s098891 (355 points)
Yes, I am using the codes from the manual, and it works if I start directly with that page...

My PHP code:

if (!isset($time0)) {
  $time0 = time();
  registerVariable('time0');  // Die Variable $time0 auch nach Ende des PHP-Codes aufbewahren
}
// Prüfung, ob die Zeit schon abgelaufen ist
// (z.B. weil der Teilnehmer die Seite neu geladen hat)
$timer = 10;  // Der Teilnehmer hat 1 Minute (60 Sekunden) Zeit zur Bearbeitung
if (time() >= $time0 + $timer) {
  goToPage('next');
}
// Die verbleibende Zeit muss auch dem JavaScript-Code bekannt gemacht werden
$remain = $time0 + $timer - time();
replace('%remain%', $remain);

My Java script code (as a text element):

<script type="text/javascript">
<!--
// Funktion zur Weiterleitung
function weiter() {

  // Den Teilnehmer zur nächsten Seite weiterleiten
  SoSciTools.submitPage();
}
// Countdown anzeigen
var date0 = new Date();
var timeout = date0.getTime() + %remain% * 1000;
function updateCountdown() {
  // Zeit berechnen
  var date = new Date();
  var time = Math.ceil((timeout - date.getTime() - 50) / 1000);  // Verbleibende Zeit in Sekunden
  // Zeit anzeigen
  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);
}
// Initialisierung der Weiterleitung
SoSciTools.attachEvent(window, "load", function(evt) {
  // Weiter-Knopf ausblenden (optional)
  SoSciTools.submitButtonsHide();
  // Zusätzlicher Timer für die Aktualisierung des Countdowns
  window.setInterval(updateCountdown, 1000);
  updateCountdown();
  // Timer für automatische Weiterleitung starten
  window.setTimeout(weiter, %remain% * 1000);
});
// -->
</script>
by SoSci Survey (328k points)
Okay, there is one variable $time0 that the questionnaire remembers throughout all pages - due to registerVariable() - you can use this only for one timer. If you need another timer, please user $time1 (or any other variable name you like) instead. Does that help?
by s098891 (355 points)
Yes it does, thank you!!!
by s098891 (355 points)
Now it works, the countdown appears as it should. However, if I don't press start or stop and just wait for the ten seconds to be over, I don't get to the next page, but I remain on the same page plus when I scroll down I can also see the following page... That's a pre-test: https://www.soscisurvey.de/belief_statements/?act=QzQqqccVLEGvyAwjiLo0hMcI
by SoSci Survey (328k points)
Well, your question demands an "answer" - so it's clear that you cannot resume with the next page, if you give no answer (via pressing start/stop). I suggest disabling the demand for an answer in the question.

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

...