Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Set a time limit for research

  • rhanzlova
  • rhanzlova's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
1 year 2 months ago #240885 by rhanzlova
Set a time limit for research was created by rhanzlova
Please help us help you and fill where relevant:
Your LimeSurvey version: 5.5.2+230109
Own server or LimeSurvey hosting: 
Survey theme/template: fruity
==================
Hello, 
I would like to ask if it is possible to set a time limit for the questionnaire? Ideally, so that the time is displayed somewhere on the screen. After the set time is up, to automatically display the final page of the questionnaire.

Is this possible? If so, can you advise me how to set this up?

Thank you very much.

Please Log in to join the conversation.

More
1 year 2 months ago #240888 by jelo
Replied by jelo on topic Set a time limit for research
Not possible with the features implemented in LimeSurvey.
I cannot remember a plugin for that either.

If you have a survey with all questions on one page (all in one survey) you can set a time limit on a single question which will control the whole survey.

The meaning of the word "stable" for users
www.limesurvey.org/forum/development/117...ord-stable-for-users

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 2 months ago - 1 year 2 months ago #240895 by Joffm
Replied by Joffm on topic Set a time limit for research
A rough idea.
At the start of the questionnaire capture the time in an equation ("stattime") {strtotime(date("H:m:s"))}

Now, if you display your survey "group by group" (you can simulate a "question by question" by putting only one question in a group)
you set the group conditions to strtotime(date("H:m:s"))-starttime<your maximum time in seconds
except your last page.

May look like this
 

Joffm
 

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 1 year 2 months ago by Joffm.

Please Log in to join the conversation.

More
5 months 2 weeks ago - 5 months 2 weeks ago #251969 by silviumatei
Replied by silviumatei on topic Set a time limit for research
For anyone who may need this, this is how I did it for a test after a training to be answered within 30 minutes:

1. As mentioned in other posts, create groups for each question. In each group, add the question and a timer question type 'Text display'. Set them to hidden if you do not want to show the timer, otherwise, just add some styling to show the descending counter.
2. All questions MUST be non-mandatory, otherwise the script will not work as it needs to take the respondent to the last group and click on the submit button.. 
3. In the timer questions, add this javascript. I highlighted the important bits in red

<script type="text/javascript" charset="utf-8">
  $(document).ready(function(){
    var totalTime = 30 * 60; // Total time for the survey in seconds (30 minutes x 60 seconds)
    var startTime = sessionStorage.getItem('surveyStartTime');
    
    if (!startTime) {
      startTime = Math.floor(Date.now() / 1000);
      sessionStorage.setItem('surveyStartTime', startTime);
    } else {
      startTime = parseInt(startTime);
    }

    var updateTimer = function() {
      var currentTime = Math.floor(Date.now() / 1000);
      var timeElapsed = currentTime - startTime;
      var timeLeft = totalTime - timeElapsed;

      var minutes = parseInt(timeLeft / 60, 10);
      var seconds = parseInt(timeLeft % 60, 10);

      minutes = minutes < 10 ? "0" + minutes : minutes;
      seconds = seconds < 10 ? "0" + seconds : seconds;

      var countdownTimer = document.getElementById('countdownTimer');
      countdownTimer.textContent = 'Time left: ' + minutes + ":" + seconds;

      if (timeLeft <= 0) {
        clearInterval(timerInterval);
        sessionStorage.removeItem('surveyStartTime'); // Clear the start time

        // Redirect to the last group or question
        // Use this line if you want to navigate directly to the last group or question.
        // Please make sure to replace the URL with your actual last group URL.
        window.location.href = " surveyURL ?newtest=Y&gid= 1000   //surveyURL is your specific URL for the survey, including the survey     
                                                                                                          //number. The gid is the ID of the last group in the survey, can be found
                                                                                                          //in the list of groups

      }
    };

    // Initialize the timer
    updateTimer();

    // Start the countdown interval
    var timerInterval = setInterval(updateTimer, 1000); // Update every second

    // Fallback in case the interval fails for some reason, ensure the page reloads after totalTime
    setTimeout(function () {
      clearInterval(timerInterval); // Stop the countdown
      sessionStorage.removeItem('surveyStartTime'); // Clear the start time
      location.reload(); // Reload the page
    }, totalTime * 1000);
  });
</script>

4. An alternative way without using js would be to add a question to store the time when starting the survey and then add another hidden question in each group to store the time difference between the current time and the starttime. If that is bigger than a value (say 30 min), then define a quota 0 to terminate. Of course, this means adding another question for an equation and another one to define the two states (1. 30 min or less or 2. more than 30 min). This last question would be used to create the quota. I find the last one more in line with the limesurvey philosophy but it think it may require more work. 
Example of such a group attached.
Last edit: 5 months 2 weeks ago by silviumatei. Reason: wrong picture attached

Please Log in to join the conversation.

Lime-years ahead

Online-surveys for every purse and purpose