Articles
JavaScript
JavaScript Digital clock
| JavaScript Digital clock |
|
|
|
| Written by Chetankumar Akarte | |
| Friday, 13 July 2007 | |
JavaScript Digital ClockIn this article we are going to design a JavaScript based Digital Clock. Here we are see use a HTML Form to show our Digital Clock. Take a look below on piece of code…
<form name = "clockForm">
.frm {
Now we have to add JavaScript which will generate Digital clock for us. Now we
define a function Display() and going to call it through Window object supports
methods setTimeout() to call same function after every 1000 milliseconds. The
Window object supports methods for setting timers that we might use to perform a
variety of functions. These methods include setTimeout() and
clearTimeout(). The
basic idea is to set a timeout to trigger a piece of script to occur at a
particular time in the future. The general syntax is
function display() { Our Clock will look like below image... Here we are also converting 24 hour Clock into 12 hour with help of conditional operator. The conditional operator is another form of an “if” condition. It takes three parameters. The syntax looks like this: (Condition) ? val1: val2. If condition is true then it will return val1 otherwise val2. example:
Please download Source Code and test it ... |
|
| Last Updated ( Friday, 13 July 2007 ) |