- Posts: 23
- Thank you received: 1
Ask the community, share ideas, and connect with other LimeSurvey users!
Please Log in to join the conversation.
Please Log in to join the conversation.
Please Log in to join the conversation.
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>
Please Log in to join the conversation.