0 votes
in SoSci Survey (English) by s109432 (110 points)
reopened by SoSci Survey

I want to set the time of each questionnaire, such as 2 min. after 2 min, it turns to next page. I try to use the scrip in the manual, but failed. why? and how to achieve it?

by SoSci Survey (328k points)
>  I try to use the scrip in the manual, but failed. why?

Depends on what script you used, where and how. If you specify that, I can most likely give you a helpful answer. Thanks.
by s109432 (110 points)
Thanks for the nice reply.
what I want is: set the time of each questionnaire, such as 1 min. after 1 min, it turns to next page.

what I did: first, random questions in different pages. second: set the limited time, such as 60s. third: show 'time is out'.

but it always failed.

here is the code I used:
first PHP code:
// PHP code on page 1
 
// shuffle list just once
if (!isset($questions)) {
  // make a list of question IDs
  $questions = array(
    'S401', 'S409',
    'S411', 'S412'
  );
  // shuffle list randomly
  shuffle($questions);
  // make lists available on all pages
  registerVariable('questions');
}
 
$i = loopPage(count($questions));
question($questions[$i]);

second PHP code:
if (!isset($time0)) {
  $time0 = time();
  registerVariable('time0');  // store variable $time0 after the end of the PHP code as well
}
// Check if time has already expired
// (e.g. because the participant reloaded the page)
$timer = 60;  // participant has 1 minute (6 seconds) to work through the page
if (time() >= $time0 + $timer) {
  goToPage('next');
}
// JavaScript code has to be told the time remaining
$remain = $time0 + $timer - time();
replace('%remain%', $remain);

third code:
<script type="text/javascript">
<!--
// Function to forward
function next() {
  // Display message (optional)
  alert("Time's up.");
  // Forward participant onto the next page
  SoSciTools.submitPage();
}
// Initialization of forwarding
SoSciTools.attachEvent(window, "load", function(evt) {
  // Hide Next button (optional)
  SoSciTools.submitButtonsHide();
  // Start timer to forward automatically
  window.setTimeout(next, %remain% * 1000);
});
// -->
</script>

1 Answer

0 votes
by SoSci Survey (328k points)

Thanks for adding the PHP code.

1) Using isset() and registerVariable() in a loop will not work. Because this combinations makes sure that - once set - the variable will not change during the interview. So, first, please remove the "second PHP code".

2) Store the "third code" as "text" in a seciotn of your choice. Make sure that the display setting is "HTML code". Let's assume the text hat the ID TX01. Then add this PHP code on your page:

text('TX01', array(
  '%remain%' => 60
));

Please not that removing the middle part will allow the respondent to reload the page and restart the timer by doing so. If you cannot allow this (you can always control the actual times in the TIME... variables), you will need an array to store the time for each page of your loop. If that's really a point, please post a related 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

...