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

Thread: JavaScript:Tutorial, Digital Clock

  1. #1
    TcM
    TcM is offline
    Code Warrior TcM is a name known to all TcM is a name known to all TcM is a name known to all TcM is a name known to all TcM is a name known to all TcM is a name known to all TcM's Avatar
    Join Date
    Aug 2006
    Posts
    11,461
    Blog Entries
    6

    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
    Last edited by Jaan; 03-09-2008 at 10:09 AM.

  2. #2
    Programming God xtraze is an unknown quantity at this point
    Join Date
    Dec 2006
    Location
    Sri lanka
    Posts
    908
    Nice, and I am now looking for an Analog clock now. Hope I can find it by Google. I will search tomorrow.

  3. #3
    Programming God AfTriX is on a distinguished road
    Join Date
    Jan 2007
    Location
    Chicago
    Posts
    586
    Thanks for the code. very useful. Text Box clock idea is good, and pretty simple code.

  4. #4
    TcM
    TcM is offline
    Code Warrior TcM is a name known to all TcM is a name known to all TcM is a name known to all TcM is a name known to all TcM is a name known to all TcM is a name known to all TcM's Avatar
    Join Date
    Aug 2006
    Posts
    11,461
    Blog Entries
    6
    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.
    Javascript: Analog Clock

    I found this one for you!

  5. #5
    Programming God AfTriX is on a distinguished road
    Join Date
    Jan 2007
    Location
    Chicago
    Posts
    586
    Seems Tcm9669 continuously digging on JavaScript mats. Nice work and thanks

  6. #6
    TcM
    TcM is offline
    Code Warrior TcM is a name known to all TcM is a name known to all TcM is a name known to all TcM is a name known to all TcM is a name known to all TcM is a name known to all TcM's Avatar
    Join Date
    Aug 2006
    Posts
    11,461
    Blog Entries
    6
    Quote Originally Posted by AfTriX View Post
    Seems Tcm9669 continuously digging on JavaScript mats. Nice work and thanks
    Welcome
    I just like JavaScript

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

  8. #8
    Programming God xtraze is an unknown quantity at this point
    Join Date
    Dec 2006
    Location
    Sri lanka
    Posts
    908
    Thanks for it lol. Nice I will add it as an html mod into a Joomla powered website I'm currently working on.

  9. #9
    Programming God AfTriX is on a distinguished road
    Join Date
    Jan 2007
    Location
    Chicago
    Posts
    586
    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

  10. #10
    Newbie doosa is an unknown quantity at this point
    Join Date
    Mar 2008
    Posts
    1

    Re: JavaScript:Tutorial, Digital Clock

    good script

+ Reply to Thread
Page 1 of 2
1 2 LastLast

Thread Information

Users Browsing this Thread

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

     

Similar Threads

  1. Creating a Clock
    By AfTriX in forum VB Tutorials
    Replies: 1
    Last Post: 05-08-2009, 10:33 AM
  2. Javascript: Analog Clock
    By TcM in forum Javascript
    Replies: 20
    Last Post: 05-28-2008, 09:01 AM
  3. Creating an analog clock with ActionScript
    By AfTriX in forum Tutorials
    Replies: 2
    Last Post: 01-07-2007, 02:19 AM
  4. Cool LCD Clock
    By AfTriX in forum Javascript
    Replies: 2
    Last Post: 01-04-2007, 01:00 AM

Bookmarks

Bookmarks

     
        Algorithms and Data Structures

        Java tutorials

        Algorithms Forum

Posting Permissions

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