Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

JavaScript:Tutorial, Digital Clock

timer clock

  • Please log in to reply
13 replies to this topic

#1 TcM

TcM

    CC Mentor

  • VIP Member
  • PipPipPipPipPipPipPipPip
  • 7563 posts

Posted 02 December 2006 - 06:22 AM

Introduction:-
This is my second tutorial and I will show you how to get the Time in a Text Box.. perhaps in a Text Box it will be useless, but it could be used in other instances!

Solution:-
This code goes in the <head> tags:-

<script language="JavaScript">

var timerID = null;
var timerRunning = false;

function stopclock (){
        if(timerRunning)
                clearTimeout(timerID);
        timerRunning = false;
}

function showtime () {
        var now = new Date();
        var hours = now.getHours();
        var minutes = now.getMinutes();
        var seconds = now.getSeconds()
        var timeValue = hours
        timeValue += ((minutes < 10) ? ":0" : ":") + minutes
        timeValue += ((seconds < 10) ? ":0" : ":") + seconds
        document.clock.face.value = timeValue;
        timerID = setTimeout("showtime()",1000);
        timerRunning = true;
}
function startclock () {
        stopclock();
        showtime();
}

</script>

And this code as the body code:-

<body onLoad="startclock()">

<form name="clock" onSubmit="0">
  <div align="center"><center><p><input type="text" name="face" size="10" value> </p>
  </center></div>
</form>

Explanation:-
I think its simple without any need of explanation.. but if you have any suggestions/questions just post them here :)

A Preview:-
Posted Image

Conclusion:-
As Always Feedback is welcome and the full source is attached!!

Attached Files


  • 0

#2 xtraze

xtraze

    CC Devotee

  • Just Joined
  • PipPipPipPipPipPip
  • 872 posts

Posted 01 January 2007 - 08:03 AM

Nice, and I am now looking for an Analog clock now. Hope I can find it by Google. I will search tomorrow.
  • 0

#3 AfTriX

AfTriX

    CC Devotee

  • Just Joined
  • PipPipPipPipPipPip
  • 541 posts

Posted 03 January 2007 - 02:22 AM

Thanks for the code. very useful. Text Box clock idea is good, and pretty simple code.
  • 0

#4 TcM

TcM

    CC Mentor

  • VIP Member
  • PipPipPipPipPipPipPipPip
  • 7563 posts

Posted 03 January 2007 - 04:40 AM

Nice, and I am now looking for an Analog clock now. Hope I can find it by Google. I will search tomorrow.


http://forum.codecal...alog-clock.html

I found this one for you!
  • 0

#5 AfTriX

AfTriX

    CC Devotee

  • Just Joined
  • PipPipPipPipPipPip
  • 541 posts

Posted 03 January 2007 - 04:46 AM

Seems Tcm9669 continuously digging on JavaScript mats. Nice work and thanks
  • 0

#6 TcM

TcM

    CC Mentor

  • VIP Member
  • PipPipPipPipPipPipPipPip
  • 7563 posts

Posted 03 January 2007 - 05:44 AM

Seems Tcm9669 continuously digging on JavaScript mats. Nice work and thanks


Welcome :)
I just like JavaScript
  • 0

#7 AfTriX

AfTriX

    CC Devotee

  • Just Joined
  • PipPipPipPipPipPip
  • 541 posts

Posted 03 January 2007 - 10:05 PM

Welcome :)
I just like JavaScript


Nice to here. Keep on improving your skills..
  • 0

#8 xtraze

xtraze

    CC Devotee

  • Just Joined
  • PipPipPipPipPipPip
  • 872 posts

Posted 06 January 2007 - 07:42 PM

Thanks for it lol. Nice I will add it as an html mod into a Joomla powered website I'm currently working on.
  • 0

#9 AfTriX

AfTriX

    CC Devotee

  • Just Joined
  • PipPipPipPipPipPip
  • 541 posts

Posted 07 January 2007 - 12:24 AM

Thanks for it lol. Nice I will add it as an html mod into a Joomla powered website I'm currently working on.


Don NOT forget to inform all the CodeCall members to tell about your site once its completed
  • 0

#10 doosa

doosa

    CC Lurker

  • Just Joined
  • Pip
  • 1 posts

Posted 08 March 2008 - 11:59 PM

good script
  • 0

#11 TcM

TcM

    CC Mentor

  • VIP Member
  • PipPipPipPipPipPipPipPip
  • 7563 posts

Posted 06 June 2008 - 10:38 AM

Welcome. JS is quite simple to master.
  • 0

#12 cryptokyle

cryptokyle

    CC Newcomer

  • Just Joined
  • PipPip
  • 11 posts

Posted 04 June 2009 - 10:30 PM

<input type="text" name="face" size="10" value>

why does the value not have ="" ? does it work the same as value="0"?
  • 0





Also tagged with one or more of these keywords: timer, clock