submit form when countdown goes to zero code example

Example: submit form when countdown goes to zero

function Update() {
    var id = 'demo'; // Display ID for time left 'demo'
    var countDownDate = new Date('Dec 3, 2020 15:34:00').getTime();
    var now = new Date().getTime();
    var distance = countDownDate - now;
    if (distance > 0) {
      var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
      var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
      var seconds = Math.floor((distance % (1000 * 60)) / 1000);

      if (distance < 0) {
        document.write("Time-up");
      } else {
        document.getElementById(id).innerHTML = (hours + "h " + minutes + "m " + seconds + "s ");
      }
      window.setTimeout('Update()', 1000);
    } else {
      document.getElementById(id).innerHTML = ("Form is submitting");
      $('.username').submit(); // Form to submit but add action="actionpage.php"
    }
  }
  Update();

Tags:

Go Example