I am new to Javascript and created a Countdown Timer with some Asp.net controls
The Probelm is that countdown timer starts with given time in hidden fields up to 00:00:00 and it's working fine now, but when I refresh the browser timer reset and starts again with default values given in hidden fields.
I searched about my problem and got the sollution with localStorage but unable to applied due to lack of knowledge in javascript. and I want to format my timer too like 01:03:40 istead of 1:3:40
Here is my Code
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
var Second = 60;
var Hour, Minute, Time;
var PreviousSelectedPage = '';
function CountDown() {
var CurrentTime = Hour + ':' + Minute + ':' + Second;
if (CurrentTime == '00:00:00') {
clearInterval(Time);
}
document.getElementById('lblDuration').innerHTML = CurrentTime;
Second--;
if (Second == -1) {
Second = 59;
Minute--;
}
if (Minute == -1) {
Minute = 59;
Hour--;
}
}
$(document).ready(function () {
Hour = document.getElementById('<%=Hour.ClientID%>').value;
Minute = document.getElementById('<%=Minute.ClientID%>').value;
Time = setInterval(function () { CountDown(); }, 1000);
});
</script>
and HTML
<div>
<asp:HiddenField ID="Hour" runat="server" Value="3" />
<asp:HiddenField ID="Minute" runat="server" Value="25" />
<label id="lblDuration"></label>
</div>
Please can anyone help me ?