I have a problem with setTimeout, and the issue is not readily apparent to me. I have a function that document.writes some stuff based on the system clock. In my <head>, I have this:
Later in the page, I have a script block that calls the function, to document.write the stuff in the appropriate place. Very simple:
Essentially, this thing should refresh itself every second, and with each pass, the text will be slightly different; different enough that I can tell that it's still running, because I'll see the text changing every second.
So, the page loads, and doSoemthing() executes as it should the very first time. Then, it reaches the setTimeout() call, and one second later, doSomething() runs a second time. Logic would dictate that if doSomething() ran a second time, setTimeout() should run a second time, which would cause doSomething() to run a third time, and so on.
This doesn't happen. When doSomething() runs the second time and it gets to the point of triggering the setTimeout() for the second time, it bombs with the error that 'doSomething() is not defined'.
What am I missing? How did doSomething() run the second time if, according to setTimeout() on it's second run, doSomething() does not exist?
Thanks in advance.
Code:
function doSomething(){
...
setTimeout("doSomething()",1000);
}
Later in the page, I have a script block that calls the function, to document.write the stuff in the appropriate place. Very simple:
Code:
<script>
doSomething();
</script>
Essentially, this thing should refresh itself every second, and with each pass, the text will be slightly different; different enough that I can tell that it's still running, because I'll see the text changing every second.
So, the page loads, and doSoemthing() executes as it should the very first time. Then, it reaches the setTimeout() call, and one second later, doSomething() runs a second time. Logic would dictate that if doSomething() ran a second time, setTimeout() should run a second time, which would cause doSomething() to run a third time, and so on.
This doesn't happen. When doSomething() runs the second time and it gets to the point of triggering the setTimeout() for the second time, it bombs with the error that 'doSomething() is not defined'.
What am I missing? How did doSomething() run the second time if, according to setTimeout() on it's second run, doSomething() does not exist?
Thanks in advance.