setInterval() and clearInterval() methods : Timer : Development : JavaScript DHTML examples (example source code) Organized by topic

JavaScript DHTML
1. Ajax Layer
2. Data Type
3. Date Time
4. Development
5. Document
6. Event
7. Event onMethod
8. Form Control
9. GUI Components
10. HTML
11. Javascript Collections
12. Javascript Objects
13. Language Basics
14. Node Operation
15. Object Oriented
16. Page Components
17. Security
18. Style Layout
19. Table
20. Utilities
21. Window Browser
Java
Java Tutorial
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
JavaScript DHTML » Development » Timer 
setInterval() and clearInterval() methods


<html>
<head>
<script type="text/javascript">
    var intval=""
    function start_Int(){
        if(intval==""){
          intval=window.setInterval("start_clock()",1000)
      }else{
          stop_Int()
      }
    }

    function stop_Int(){
        if(intval!=""){
          window.clearInterval(intval)
          intval=""
          myTimer.innerHTML="Interval Stopped"
      }
    }

    function start_clock(){
        var d=new Date()
        var sw="am"
        var h=d.getHours()
        var m=d.getMinutes() ""
        var s=d.getSeconds() ""
        if(h>12){
          h-=12
          sw="pm"
      }
        if(m.length==1){
          m="0" + m
      }
        if(s.length==1)  {
          s="0" + s
      }
        myTimer.innerHTML=h + ":" + m + ":" + s + " " + sw
    }
</script>
</head>

<body>
<span id="myTimer">Interval Stopped</span>
    <br><br><br>
    <input type="button" value="Start" onclick="start_Int()">
    <input type="button" value="Stop" onclick="stop_Int()">
</body>

</html>


           
       
Related examples in the same category
1. Using a Timer
2. A Countdown Timer
3. Timer Events Demo
4. Timer Events Demo 2
5. Accessing Document Contents
6. A Timeout Processing Example
Home | Contact Us
Copyright 2003 - 07 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.