samedi 8 août 2020

codeigniter start timer on button click and display

Quick FYI: I am learning. I have some experience in PHP and very little to none in java. Ive been downed on posts before because of this. So trying one more time.

I am trying to start a timer for 24 hours on a button click, and display this timer. After this 24 hours, it updates tables in database. This button is inside an if statement which seems to make it harder.

So when this button is clicked, it starts the 24 hour timer, HH:MM:SS. I have tried a few timer scripts, but im unsure how to use them. Again, no real experience in java. This was the timer script i found.

 <script> 
function Timer(duration, display) 
{
    var timer = duration, hours, minutes, seconds;
    setInterval(function () {
        hours = parseInt((timer /3600)%24, 10)
        minutes = parseInt((timer / 60)%60, 10)
        seconds = parseInt(timer % 60, 10);

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

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

                --timer;
    }, 1000);
}

jQuery(function start($) 
{
    var twentyFourHours = 24 * 60 * 60;
    var display = $('#remainingTime');
    Timer(twentyFourHours, display);
});


 
 </script>
 

And this is the statement:

 <? if($provinces['nation_name'] == "") {
     '<center><button onclick="start()">Start Nation</button></center>';
          } 
?>

I think my problem is getting it to read the function in the IF statement. I haven't gotten to updating after timer, just trying to get this to work first.

Aucun commentaire:

Enregistrer un commentaire