- Posts: 23
- Thank you received: 1
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Set a time limit for research
- rhanzlova
- Topic Author
- Offline
- Junior Member
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.
- jelo
- Offline
- Platinum Member
- Posts: 5033
- Thank you received: 1257
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
- Offline
- LimeSurvey Community Team
- Posts: 12940
- Thank you received: 3979
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
Please Log in to join the conversation.
- silviumatei
- Offline
- New Member
- Posts: 2
- Thank you received: 0
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
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.<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>
Example of such a group attached.
Please Log in to join the conversation.