Advanced Computer

Javascript

Assignment 5    -   Add a Clock  on a Division Layer (Color)

 

CLOCKDIV.HTML

<html>

<head>

 

<script type= "text/javascript" src="clockdiv.js">

</script>

 

</head>

 

<div id='lyr' style='position:absolute;

top:73px;left:12px;width:250px;height:50px;z-index:10;

background-color:orange'>

 

<body onload = "tick()">

 

<form id = "f">

 

<h2>JavaScript time is now:</h2>

<h4>E.S.T: <input type="text" name="clock"></h4>

 

</form>

</div>

</html>

 

 
 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


CLOCKDIV.JS

 

function tick()

{

 

                // create a new Date Object

                var now = new Date();

 

                // extract the current hours, minutes and seconds

                var hh = now.getHours();

                var mn = now.getMinutes();

                var ss = now.getSeconds();

 

                // ensure each components has two digits

                if( hh <= 9 ) hh = "0" + hh;

                if( mn <= 9 ) mn = "0" + mn;

                if( ss <= 9 ) ss = "0" + ss;

 

                // assign the current time string to the form field

                document.forms.f.clock.value = hh+ ": " +mn+ ": " +ss;

 

                // set the interval to one second

                window.setTimeout( "tick()", 1000 );

}