views:

248

answers:

3

how do i make the div refresh, say after 10 secs and execute the run_query() function without clicking on the button?

<script src="scripts/ajax.js" type="text/javascript"></script> 



<div id="quote"><strong>Quote of the Day</strong></div>
<div><a style="cursor:pointer" onclick="run_query()">Next quote …</a></div>
+11  A: 

Use setInterval function.

setInterval(function(){run_query();}, 10000);

For the initial load you can do that from the server side code.

rahul
it works, but initially it loads nothing.
fuz3d
@fusion: Well you can run the function once after page load: `winodw.onload = function(){run_query()}`
Felix Kling
@felix, did that. now it doesn't even refresh every 10 sec .. `<script type="text/javascript"> winodw.onload = function(){ run_query(); } setInterval(run_query, 10000);</script>` neither does it load nor refresh.
fuz3d
There is a typo in window. Its window and not winodw.
rahul
thanks, both of you!
fuz3d
@fusion: In such cases, using Firebug for Firefox is really helpful to find syntax errors.
Felix Kling
+1  A: 
setTimeout("run_query()",10000);
slier
That runs the function only once after 10 seconds.
Felix Kling
he dosent say that he want to run his function every 10 seconds
slier
+1  A: 

check this article on the settimeout,setiterval will give you more idea

http://www.elated.com/articles/javascript-timers-with-settimeout-and-setinterval/

Pranay Rana