Search HouseOfScripts.com

 

All Scripts        JavaScripts        ASP Scripts        Other Scripts

 

  How to build a Clock on the Web? asp, send, email, cdonts, link, recordset, hyper, hyperlink, create, list, box, dependant, dynamic

If you want to buld clock, you need to know a few Javascript functions. If you do not want to build it, check Clock on the Web and Another Clock on the Web pages.

First we have to build the it.
Everything starts with Date(). If you need a clock that will show you everything, use this command:

HEAD:
< script language="JavaScript">
function sdate(){
document.form1.fdate.value = Date();
}
< /script>
BODY:
< body onload="sdate()">
< form name="form1">
< input type=text name="fdate">
< /form>
< /body>



If this is all you want, you can go to section How to Start Ticking.

Now, if we are not satisfy with this, we start using functions: : getSeconds(), getMinutes(), getHours(), getDay(), getDate(), getMonth() and getYear()

Lets say we want to see Hours:Minutes:Seconds

HEAD:
<script language="JavaScript">
function sdate(){
var fdate = new Date();
document.form1.fdate.value = fdate.getHours() + ":" + fdate.getMinutes() + ":" + fdate.getSeconds();
}
</script>
BODY:
< body onload="sdate()">
< form name="form1">
< input type=text name="fdate">
< /form>
< /body>


You can build custom clock based on example above.

Now, it is time for our clock to start ticking. It is simple, basicaly we need to insert setTimeout("function()", seconds) command into our script.

HEAD:
<script language="JavaScript">
function sdate(){
var fdate = new Date();
document.form1.fdate.value = fdate.getHours() + ":" + fdate.getMinutes() + ":" + fdate.getSeconds();
setTimeout("sdate()",1000);
}
</script>


 

 


Home       Scripts       Active WebTools       Web Templates       Forum       Tools        Hosting       Questions/Comments       Add/Request