Home Start countdown after php page load
Reply: 0

Start countdown after php page load

user2475
1#
user2475 Published in April 19, 2018, 8:52 pm

I am trying to create a browser training button. When the user clicks the " Brench Press" button his "Strength" increases by a php file that i've set in the form action and it checks some values and inserts values to the database that shows up.

What my problem and what i would like some help with is to implement my clock function that sets a countdown from 30 seconds to 0. This should be a countdown that the users has to watch and wait for untill he can "train" again. So somehow i need to write this clock function to output after the php file has been loaded and not onclick on the button as of now. And also for the clock not to refresh it's countdown on page refresh but keep going.

What i tried to do is to create a session with the function call inside and send it to the site so it loads after the php file has loaded but it doesn't seem to work.

$_SESSION['CountDownBenchPress'] = "<script> countdown(); </script>";

var time = 30;
function countdown()
{
  if(time==0)
  {
    window.location.reload();
  }
  else
  {
    tmptime = time;
    dayTime = 24*60*60;
    hourTime = 60*60;
    minutesTime = 60;

    days = Math.floor(tmptime/dayTime);
    tmptime = tmptime - days*dayTime;

    hours = Math.floor(tmptime/hourTime);
    tmptime = tmptime - hours*hourTime;

    minutes = Math.floor(tmptime/minutesTime);
    tmptime = tmptime - minutes*minutesTime;

    seconds = tmptime;
    tidtext="";
    if(days>0)
      tidtext = days+ hours + " hours " + minutes + " minutes " + seconds + " seconds";
    else if(hours>0)
      tidtext = hours + " hours " + minutes + " minutes " + seconds + " seconds";
    else
      tidtext =  minutes + " minutes " + seconds + " seconds";

    document.getElementById('timer').innerHTML = tidtext;
    time--;
    setTimeout("countdown()", 1000);
  }
}
<form class="" action="" method="">
            <td data-th="Workout"><input type="submit" onclick="countdown()" name="" value="Bench Press"></td>

            <div id="timer"></div>

          </form>

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.298344 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO