setTimeout

Discussion in 'Javascript' started by linuxnooby@yahoo.com.au, Aug 26, 2007.

  1. Guest

    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
     
    , Aug 26, 2007
    #1
    1. Advertising

  2. Alan Raskin Guest

    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
     
    Alan Raskin, Aug 26, 2007
    #2
    1. Advertising

  3. Guest

    that works!!

    Thank you very much

    Dave
     
    , Aug 26, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andy Pickering

    Smart navigation and js setTimeout

    Andy Pickering, Oct 24, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    492
    Andy Pickering
    Oct 27, 2003
  2. j van c

    settimeout

    j van c, Dec 5, 2003, in forum: HTML
    Replies:
    5
    Views:
    482
    Nico Schuyt
    Dec 7, 2003
  3. JR

    setTimeout

    JR, Apr 15, 2004, in forum: HTML
    Replies:
    3
    Views:
    535
    Whitecrest
    Apr 15, 2004
  4. =?Utf-8?B?RQ==?=

    javascript setTimeout does not work

    =?Utf-8?B?RQ==?=, May 2, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    8,792
    =?UTF-8?B?R8O2cmFuIEFuZGVyc3Nvbg==?=
    May 2, 2006
  5. Colin Brown

    socket settimeout ?

    Colin Brown, Dec 3, 2003, in forum: Python
    Replies:
    0
    Views:
    603
    Colin Brown
    Dec 3, 2003
Loading...

Share This Page