Click here to Skip to main content
15,881,033 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
HTML
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Digitl clock</title>
<style type="text/css">
#time{
font-size:50pt;
}
</style>
</head>
<body  önload="timer()">

<script type="text/javascript" language=javascript>
//var digiclock = "00:00:00";
i = 0;
function timer()
{

    var digiformat = "";
	if(i>3599)
	{
		var H = Math.floor(i/3600);
	}
	else
	{
		var H = 0;
	}
	
	var M = i - (H*3600)
	
	if(M>59)
	{
		M = Math.floor(M/60)
	}
	else
	{
		M = 0
	}	
	var S = i - (M*60)	
	if(H<10)
	{
		H = "0"+H;
	}
	if(M<10)
	{
		M = "0"+M;
	}
	if(S<10)
	{
		S = "0"+S;
	}
	
//	document.getElementById('time').innerHTML = H+":"+M+":"+S;
    document.getElementById('lblTimer').innerHTML = H+":"+M+":"+S;
    setTimeout('timer()', 1000);
    i++;
}
</script>

<%--<asp:HiddenField ID="hidenfld" runat="server" />--%>
<asp:Label ID="lblTimer" runat="server" Font-Size="30px"    ></asp:Label>     
<input type=button ID="btnrefresh"  runat="server" value="refresh"/>

</body>
</html>

How can I avoid refresh of counter, I tried all the ways.
Posted
Updated 10-Jan-12 23:19pm
v2
Comments
Pete O'Hanlon 11-Jan-12 5:30am    
Only post your question once. I am removing your other instance of this question.
Shahin Khorshidnia 11-Jan-12 5:50am    
Wich counter?
Smithers-Jones 11-Jan-12 7:50am    
Use proper subjectlines, yours isn't very descriptive.

Maybe something like this will help you:

ASP.NET
<body onload="timer()">
    <form id="form1" runat="server">
    <div>
        <asp:hiddenfield runat="server" id="timerValue" value="0" xmlns:asp="#unknown" />
        <script type="text/javascript" language="javascript">
            function timer() {
                var timerValue = document.getElementById("timerValue");
                var i = timerValue.value;
                var digiformat = "";

                if (i > 3599) {
                    var H = Math.floor(i / 3600);
                } else {
                    var H = 0;
                }

                var M = i - (H * 3600)

                if (M > 59) {
                    M = Math.floor(M / 60)
                } else {
                    M = 0
                }
                
                var S = i - (M * 60)
                if (H < 10) {
                    H = "0" + H;
                } 
                if (M < 10) {
                    M = "0" + M;
                }
                if (S < 10) {
                    S = "0" + S;
                }

                document.getElementById('lblTimer').innerHTML = H + ":" + M + ":" + S;
                setTimeout('timer()', 1000);
                i++;
                timerValue.value = i;
            }
        </script>
        <label id="lblTimer" style="font-size:30px"></label>     
        <asp:button runat="server" text="Refresh" xmlns:asp="#unknown" />
    </div>
    </form>
</body>
 
Share this answer
 
Use hidden fields

1. Read i from Server (First line of your function)

2. after i++; , use __doPostBack to post the value to server.

I think after every refresh the i is not flashing.
 
Share this answer
 
v5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900