Click here to Skip to main content
15,887,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello,

I wanted my PHP form to be submitted at end of duration, for example the duration is 5 minutes, so as the time reach to 0 the form submits automatically.

I tried the below but it submits the form immediately while I want it to be submitted after the timer reaches to 0.
please help.
Thanks in advance.

What I have tried:

JavaScript
$(function () {

        var duration = 60 * minutes,
        display = $('#time');
    startTimer(duration, display); 
    
});
function startTimer(duration, display) {

    var timer = duration, minutes, seconds;
  var t =  setInterval(function () {
        minutes = parseInt(timer / 60, 10);
        seconds = parseInt(timer % 60, 10);

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

        display.text(minutes + ":" + seconds);

        if (--timer < 0) {
            timer = 0;
            clearInterval(t);
            $('#frmquiz').submit();
        }
    }, 1000);
}
Posted
Updated 26-Dec-23 1:12am
v4

1 solution

Answered only to remove from unanswered queue - solved by OP.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900