Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Javascript (http://www.velocityreviews.com/forums/f68-javascript.html)
-   -   setTimeout (http://www.velocityreviews.com/forums/t932601-settimeout.html)

linuxnooby@yahoo.com.au 08-26-2007 03:03 AM

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


Alan Raskin 08-26-2007 03:19 AM

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

linuxnooby@yahoo.com.au 08-26-2007 04:18 AM

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.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57