setTimeout

L

linuxnooby

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
 
A

Alan Raskin

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top