I want this to start running as soon as this page is loaded. It is for a Drupal site (a CMS), so I do not want to add a 'onload' to the body tag. I also don't want to alter the header text (which will permanently load to every page from now on). I just want to do this locally within the HTML. This doesn't work; I think it is obvious what I am trying to do; it's just a timer: <h1 id="header">Old Header</h1> <script type="text/javascript"> document.getElementById("header").innerHTML=0; var t; var c = 1; while(true){ document.getElementById('header').inerHTML=c; c=c+1; timedCount(1000); //t=setTimeout("timedCount()",1000); <--if I replace the above line with this; it does not work either. } </script> Code (markup):
Try this, <h1 id="header">Old Header</h1> <script type="text/javascript"> document.getElementById("header").innerHTML=0; var t; var c = 1; function timedCount() { document.getElementById('header').innerHTML=c; c=c+1; t=setTimeout(timedCount,1000); } timedCount(); </script> Code (markup):