[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

setTimeout() bug



Hey all,

I'm familiar with the setTimeout() method (used it to write some scrollbars
and other annoying stuff), but have run into an instance where I can't get
it to work.

Th following line evaluates IMMEDIATELY, regardless of what how long I tell
it to wait:

loopID = setTimeout(loopBackground(),1000)

Take a look at my code below or try this URL for an example:
http://www.his.com/~smithers/freq/beta/bgcolor.html

What happens is that the loopBackground function is immediately called and
the bgColor set, then after the 1 second pause I get and error message
'<undefined>'.  I'm a little dizzy with exhaustion right now, so I may have
missed something basic.  Please HELP.

<HTML><HEAD>
<SCRIPT LANGAUGE="Javascript">
<!-- Start hiding
var COLOR = 999999

function loopBackground() {
  if (COLOR > 0) {
   document.bgColor = '#' + COLOR
   alert(COLOR)
   COLOR -= 111111
   loopID = setTimeout(loopBackground(),1000)
  } else {
    document.bgColor = '#000000'
    // clearTimeout(loopID)
  }
}
// --> </SCRIPT></HEAD>

<BODY BGCOLOR="#FFFFFF" TEXT="#CCCCCC">
<FORM NAME="background">
 <INPUT TYPE="button" VALUE="Start bgColor WARP"
   onClick="loopBackground()">
</FORM>
I welcome your comments and suggestions, please send them to 
<I><A HREF="mailto:aug@ix.netcom.com";>
  aug@ix.netcom.com
</A></I>
</BODY></HTML>

ANDY AUGUSTINE
aug@ix.netcom.com

--------------------------------------------------------------------
This message came from the mailing list javascript. For help using the
mailing list software, please send a message to 'majordomo@obscure.org'
with the message body 'help'. To unsubscribe, send a message to
'majordomo@obscure.org' with the message body 'unsubscribe javascript'.