<script>
function startTimer() {
var date = "<?php echo $date ?>"; // dynamic date
var time = "<?php echo $time ?>"; // dynamic time current time to 40 minutes (example)
var startTime = new Date(date);
var endTime = new Date(startTime.getTime() + time * 60000);
console.log(date + " " + time);
var timerInterval = setInterval(function() {
var remainingTime = endTime - new Date();
if (remainingTime <= 0) {
clearInterval(timerInterval);
$('#examTime').text('Time\'s up!');
$('#timeUpModal').modal('show');
// auto Submit Form
setTimeout(() => {
submitForm();
}, 7000);
} else {
var minutes = Math.floor((remainingTime / (1000 * 60)) % 60);
var seconds = Math.floor((remainingTime / 1000) % 60);
minutes = (minutes < 10 ? '0' : '') + minutes;
seconds = (seconds < 10 ? '0' : '') + seconds;
$('#examTime').text('Time Remaining: ' + minutes + ':' + seconds);
}
}, 1000);
}
startTimer();
function submitForm()
{
// if you use this method can you check (name='submit') --> change name submit1 or else any words
document.getElementById('objForm').submit();
}
</script>