I have a working countup timer
in tutorial1.php
file. What I want to do is when user click Stop
button the timer will stop and send the duration to result.php
file. The timer is in javascript, but I am new in javascript. Right now I am trying using session
but it doesn't work. I don't want to use post or get because I use it for another calculation.
Below is the code:
1) tutorial1.php
<?php session_start(); ?>
<h2 class="pull-right label label-primary"> Timer : <span id='timer'></span> </h2> //the countup timer
<?php $_SESSION['time'] = 'myVar'; ?>
<button id='".$j."' class='next btn btn-primary finish' onclick='myStopFunction()' name='Finish' type='submit'>Stop it!</button> //Stop button
<script>
//TIMER
var myVar = setInterval(function(){ timedCount() }, 1000);
var c = 0;
var t;
timedCount();
function timedCount() {
var hours = parseInt( c / 3600 ) % 24;
var minutes = parseInt( c / 60 ) % 60;
var seconds = c % 60;
var result = (hours < 10 ? "0" + hours : hours) + ":" + (minutes < 10 ? "0" + minutes : minutes) + ":" + (seconds < 10 ? "0" + seconds : seconds);
$('#timer').html(result);
c = c + 1;
}
function myStopFunction() {
clearInterval(myVar);
}
</script>
2) result.php
Your time is <?php echo $_SESSION['time']; ?>
How to make it work? Or is there any other easy solution for my problem? Thanks in advance.