![]() |
setTimeout
Hi
I am having a problem with setTimeout setTimeout("Jumpup('kangaroodiv',counter)",10); Mozilla error console says "counter not defined". Counter is defined, so I must have the SetTimeout syntax wrong. Below is the function it is used in Any help appreciated Dave function Jumpup(divname,counter) { top = document.getElementById(divname).style.marginTop topvalue = top.substr(0,top.length -2) counter++; if (counter < 40) { topvalue = (topvalue * 1) - 1 ; } else { topvalue = (topvalue * 1) + 1 ; } topstring = topvalue.toString() + 'px'; document.getElementById(divname).style.marginTop = topstring; if (topvalue == 0 ) { return; } setTimeout("Jumpup('kangaroodiv',counter)",10); } cheers Dave |
Re: setTimeout
linuxnooby@yahoo.com.au wrote:
> Hi > > I am having a problem with setTimeout > > setTimeout("Jumpup('kangaroodiv',counter)",10); > > Mozilla error console says "counter not defined". Counter is defined, > so I must have the SetTimeout syntax wrong. > Below is the function it is used in Any help appreciated > > Dave > > > function Jumpup(divname,counter) { > > top = document.getElementById(divname).style.marginTop > topvalue = top.substr(0,top.length -2) > > counter++; > if (counter < 40) > { > topvalue = (topvalue * 1) - 1 ; > } > else > { > topvalue = (topvalue * 1) + 1 ; > } > > topstring = topvalue.toString() + 'px'; > document.getElementById(divname).style.marginTop = topstring; > > if (topvalue == 0 ) > { > return; > } > > setTimeout("Jumpup('kangaroodiv',counter)",10); > > } > > cheers Dave > "counter" is an argument of the Jumpup function. It exists while the function is being executed, but is *not* visible ("in scope") when the timer goes off and "Jumpup('kangaroodiv',counter)" executes. Hence an error occurs. Try setTimeout("Jumpup('kangaroodiv'," + counter + ")",10); instead; this will pass the value of "counter" as required. - Alan |
Re: setTimeout
that works!!
Thank you very much Dave |
| All times are GMT. The time now is 11:55 AM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.