+ Reply to Thread
Results 1 to 2 of 2

Thread: Timer

  1. #1

    Timer

    I`d like to display a clock on my website so visitors can keep track of time while they are browsing website
    I`d like to do that without page being completly reloaded because i tried that and i couldn`t , a friend told me
    to use Jquery but i want this in JavaScript

  2. #2
    Junior Member
    Join Date
    Apr 2012
    Posts
    17
    It is so simple , you are going to use the local time of computer to be the clock
    and set interval to 1 sec and when it ticks it will update the time.
    Code:
    <script type="text/javascript">
    function myFunction()
    {
    setInterval(function(){myTimer()},1000);
    }
    
    function myTimer()
    {
    var d=new Date();
    var t=d.toLocaleTimeString();
    document.getElementById("demo").innerHTML=t; // change demo to your tag ID
    }
    </script>
    And in HTML create a TAG with ID "demo"
    Code:
    <p id="demo"></p>

+ Reply to Thread

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