+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: JavaScript:Tutorial, Digital Clock

  1. #1
    Join Date
    Aug 2006
    Posts
    11,209
    Blog Entries
    6
    Rep Power
    101

    JavaScript:Tutorial, Digital Clock

    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:-

    Code:
    <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:-

    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:-


    Conclusion:-
    As Always Feedback is welcome and the full source is attached!!
    Attached Files Attached Files
    Last edited by Jaan; 03-09-2008 at 08:09 AM.

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    xtraze is offline Programming God
    Join Date
    Dec 2006
    Location
    Sri lanka
    Posts
    911
    Rep Power
    0
    Nice, and I am now looking for an Analog clock now. Hope I can find it by Google. I will search tomorrow.

  4. #3
    AfTriX is offline Programming God
    Join Date
    Jan 2007
    Location
    Chicago
    Posts
    586
    Rep Power
    0
    Thanks for the code. very useful. Text Box clock idea is good, and pretty simple code.

  5. #4
    Join Date
    Aug 2006
    Posts
    11,209
    Blog Entries
    6
    Rep Power
    101
    Quote Originally Posted by xtraze View Post
    Nice, and I am now looking for an Analog clock now. Hope I can find it by Google. I will search tomorrow.
    http://forum.codecall.net/javascript...log-clock.html

    I found this one for you!

  6. #5
    AfTriX is offline Programming God
    Join Date
    Jan 2007
    Location
    Chicago
    Posts
    586
    Rep Power
    0
    Seems Tcm9669 continuously digging on JavaScript mats. Nice work and thanks

  7. #6
    Join Date
    Aug 2006
    Posts
    11,209
    Blog Entries
    6
    Rep Power
    101
    Quote Originally Posted by AfTriX View Post
    Seems Tcm9669 continuously digging on JavaScript mats. Nice work and thanks
    Welcome
    I just like JavaScript

  8. #7
    AfTriX is offline Programming God
    Join Date
    Jan 2007
    Location
    Chicago
    Posts
    586
    Rep Power
    0
    Quote Originally Posted by Tcm9669 View Post
    Welcome
    I just like JavaScript
    Nice to here. Keep on improving your skills..

  9. #8
    xtraze is offline Programming God
    Join Date
    Dec 2006
    Location
    Sri lanka
    Posts
    911
    Rep Power
    0
    Thanks for it lol. Nice I will add it as an html mod into a Joomla powered website I'm currently working on.

  10. #9
    AfTriX is offline Programming God
    Join Date
    Jan 2007
    Location
    Chicago
    Posts
    586
    Rep Power
    0
    Quote Originally Posted by xtraze View Post
    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

  11. #10
    doosa is offline Newbie
    Join Date
    Mar 2008
    Posts
    1
    Rep Power
    0

    Re: JavaScript:Tutorial, Digital Clock

    good script

+ Reply to Thread
Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

There are currently 2 users browsing this thread. (0 members and 2 guests)

Similar Threads

  1. Replies: 0
    Last Post: 10-15-2011, 03:55 AM
  2. Javascript: Analog Clock
    By TcM in forum JavaScript Tutorials
    Replies: 23
    Last Post: 06-09-2011, 01:05 PM
  3. Javascript analog clock help needed!
    By welton122 in forum JavaScript and CSS
    Replies: 1
    Last Post: 02-09-2011, 06:05 AM
  4. A digital clock in Console
    By kiekkopojka8 in forum C# Programming
    Replies: 5
    Last Post: 02-08-2010, 05:13 AM
  5. Updating Digital Clock Java
    By Turk4n in forum Classes and Code Snippets
    Replies: 0
    Last Post: 01-07-2010, 11:38 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts