How to use Window Object ClearTimeout in JavaScript

In this article I am going to explain about window object ClearTimeout() Method.
  • 2413

JavaScript Window object ClearTimeout() Method

JavaScript ClearTimeout() Method use for clear current timer passes to method that set to the SetTimeout() method.

Syntax

clearTimeout(settimeout id)

Example

<html>

<head>

    <script type="text/javascript">

        var c = 0;

        var t;

        var tsn = 0;

 

        function countTime() {

            document.getElementById('str').value = c;

            c = c + 1;

            t = setTimeout("countTime()", 1000);

        }

 

        function Timer() {

            if (!tsn) {

                tsn = 1;

                countTime();

            }

        }

 

        function StopTime() {

            clearTimeout(t);

            tsn = 0;

        }

    </script>

</head>

<body>

    <form>

    <p>

        click button for start and stop</p>

    <textarea id="str"></textarea>

    <input type="button" value="Start" onclick="Timer()" />

    <input type="button" value="stop" onclick="StopTime()" />

    </form>

</body>

</html>

 

Output


timeout.gif

 

You may also want to read these related articles: here
 
Ask Your Question 
 
Got a programming related question? You may want to post your question here
 

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.