<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Dot Net Thoughts &#187; Timer functions</title>
	<atom:link href="http://www.dotnetthoughts.net/tag/timer-functions/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dotnetthoughts.net</link>
	<description>thoughts about .Net, WPF, Sharepoint, Javascript and more.</description>
	<lastBuildDate>Wed, 01 Sep 2010 09:53:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Set timeout and Clear timeout in Javascript</title>
		<link>http://www.dotnetthoughts.net/2007/05/16/set-timeout-and-clear-timeout-in-javascript/</link>
		<comments>http://www.dotnetthoughts.net/2007/05/16/set-timeout-and-clear-timeout-in-javascript/#comments</comments>
		<pubDate>Wed, 16 May 2007 04:57:21 +0000</pubDate>
		<dc:creator>Anuraj P</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[ASP.Net Chat script]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Timer functions]]></category>

		<guid isPermaLink="false">http://anuraj.wordpress.com/2007/05/16/set-timeout-and-clear-timeout-in-javascript/</guid>
		<description><![CDATA[Timing events in javascript helps to execute a function, after a specified time interval. setTimeout() &#8211; Executes a code some time in the future. clearTimeout() &#8211; Cancel an existing setTimeout event. var somevariable = setTimeout(&#34;function_to_execute&#34;,milliseconds); clearTimeout(somevariable) Here is sample code snippet for a Javascript counter using SetTimeout and ClearTimeout functions. Timing events in javascript helps [...]]]></description>
			<content:encoded><![CDATA[<p>Timing events in javascript helps to execute a function, after a specified time interval.</p>
<p>setTimeout() &#8211; Executes a code some time in the future.<br />
clearTimeout() &#8211; Cancel an existing setTimeout event.</p>
<pre class="brush: jscript;">
var somevariable = setTimeout(&quot;function_to_execute&quot;,milliseconds);
clearTimeout(somevariable)
</pre>
<p>Here is sample code snippet for a Javascript counter using SetTimeout and ClearTimeout functions.</p>
<p>Timing events in javascript helps to execute a function, after a specified time interval.</p>
<p>setTimeout() &#8211; Executes a code some time in the future.<br />
var somevariable = setTimeout(&#8220;function_to_execute&#8221;,milliseconds);</p>
<p>clearTimeout() &#8211; Cancel an existing setTimeout event.<br />
clearTimeout(somevariable)</p>
<p><strong><u>Code of a javascript counter.</u></strong></p>
<pre class="brush: xml;">
&lt;html&gt;
&lt;head&gt;
    &lt;title&gt;Javascript counter&lt;/title&gt;

    &lt;script type=&quot;text/javascript&quot; language=&quot;Javascript&quot;&gt;
        var var_counter = 0;
        var var_timer;
        function start_counter() {
            document.getElementById(&quot;counter&quot;).innerText = var_counter;
            var_counter++; var_timer = setTimeout(&quot;start_counter()&quot;, 1000);
        }
        function stop_counter() {
            clearTimeout(var_timer);
        }
    &lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
    Counter :
    &lt;div id=&quot;counter&quot;&gt;
    &lt;/div&gt;
    &lt;br /&gt;
    &lt;button onclick=&quot;start_counter()&quot;&gt;
        Start&lt;/button&gt;
    &lt;button onclick=&quot;stop_counter()&quot;&gt;
        Stop&lt;/button&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>if var_counter variable is local scope instead of global, every time clicking on start button will initialize the counter. </p>
<p>There is two more timing related functions available in Javascript.</p>
<p>SetInterval() and ClearInterval() &#8211; It is almost same as the SetTimeout and clearTimeout, only difference is setTimeout() triggers expression only once, setInterval() keeps triggering expression again and again (unless you tell it to stop). And the Syntax are same. You can write the counter with SetInterval very easily that setTimeOut</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dotnetthoughts.net/2007/05/16/set-timeout-and-clear-timeout-in-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
