Timer in HTML page by java script

Timer in HTML page by java script


<html>
<head>
    <script language="javascript">
        var dt = null;
        setTimeout(setTime, 100);
        function setTime() {
            if (dt == null)
                dt = new Date();
            var totalseconds = parseInt(((new Date()) - dt) / 1000, 10);
            var hh = parseInt(totalseconds / (60 * 60), 10);
            var mm = parseInt((totalseconds - (hh * 60 * 60)) / 60, 10);
            var ss = parseInt(totalseconds - (hh * 60 * 60) - (mm * 60), 10);
            document.getElementsByName("txttimer")[0].value = (hh > 9 ? hh : ('0' + hh)) + ":" + (mm > 9 ? mm : ('0' + mm)) + ":" + (ss > 9 ? ss : ('0' + ss));
            setTimeout(setTime, 1000);
        }
    </script>
</head>
<body>
    <div style="margin: auto; text-align: center;">
        <input type="text" readonly="readonly" name="txttimer" style="text-align: center;
            color: Blue; font-weight: bold; border: solid 1px red; padding: 5px; width: 100px;
            height: 27px; margin: auto;" />
    </div>
</body>
</html>


Post a Comment

Previous Post Next Post