I have a count down timer in the Hours left field, to find the hours left. I also have a field to enter the total estimated time and upon enetering the value of total estimated time, the timer will start.
Now my requirement is when ever i changed the total estimated time, i want to get the value of timer, at that time to calculate the new value from where the timer starts again.
for eg : my first total estimated time = 3 and when the timer reaches 02:00:00, i changed the total estimated time to 5, so my timer will reset from 04:00:00 (logic : 5-3+2 = 4 or 5-(3-2) = 4)
so i want the current countdown timer value.HOw can i do this???
my Timer.js file :
var Timer;
var TotalSeconds;
function CreateTimer(TimerID, Time) {
Timer = document.getElementById(TimerID);
TotalSeconds = Time;
UpdateTimer()
window.setTimeout("Tick()", 1000);
}
function Tick() {
if (TotalSeconds <= 0) {
alert("Time's up!")
return;
}
TotalSeconds -= 1;
UpdateTimer()
window.setTimeout("Tick()", 1000);
}
function UpdateTimer() {
var Seconds = TotalSeconds;
var Days = Math.floor(Seconds / 86400);
Seconds -= Days * 86400;
var Hours = Math.floor(Seconds / 3600);
Seconds -= Hours * (3600);
var TimeStr = ((Days > 0) ? Days + " days " : "") + LeadingZero(Hours) + ":" + LeadingZero(Minutes) + ":" + LeadingZero(Seconds);
Timer.innerHTML = TimeStr;
}
function LeadingZero(Time) {
return (Time < 10) ? "0" + Time : + Time;
}
this is where i am calling my timer.
<script type="text/javascript" src="./Timer.js"></script>
<div id='timer'></div>
[% IF bug.estimated_time >0 %]
<script type="text/javascript">
var time;
time = CreateTimer("timer",[% bug.estimated_time %]*3600);
window.onload = CreateTimer("timer",[% bug.estimated_time %]*3600);
</script>
[% END %]
here i want to call the function
<tr>
<td align="center">
<input name="estimated_time" id="estimated_time"
value="[% PROCESS formattimeunit
time_unit=bug.estimated_time %]"
size="6" maxlength="6" onchange="updateRemainingTime();">
<input type = "Hidden" name="estimate_time" id="estimate_time" value="[% bug.estimated_time %]" size="6" maxlength="6">
</td
on calling updateRemainingTime(), i want to take the current value of timer and using that, i want to reset the counter using the above mentioned logic....