Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Aug 2002
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Passing Functions Array Objects

    I'm trying to generic 'atise the following DHTM/Javascript scrolling window function.
    The function gets passed an array Object which contains the id of the scrolling DIV layer.
    It works on the first passing, however this line -

    scrTmId = setTimeout("scrollDown("+wndo+","+num+","+inc+")",scrTimer);

    results in an javascript error "] expected"

    I can't work out how to pass back the orginal refernce to the function

    The full page can we see at www.rarepleasures.co.uk/index2.htm

    function scrollDown(wndo,num,inc) {
    if (!pgLoaded) return;
    var y = parseInt(wndo[num].cnt.css.top);

    if (y>-wndo[num].maxY) {
    wndo[num].cnt.shiftBy(0,-inc);
    scrTmId = setTimeout("scrollDown("+wndo+","+num+","+inc+")",scrTimer);
    }
    }

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    Mumbai, India
    Posts
    218
    Thanks
    0
    Thanked 0 Times in 0 Posts
    See this thread :
    setTimeout()

  • #3
    New to the CF scene
    Join Date
    Aug 2002
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Passing Functions Array Objects

    I've tried those methods, but the object still doesn't get passed back to the function and I generate the same error.

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Location
    Atlanta, GA.
    Posts
    313
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You cannot pass objects in the setTimeout function. The most you can pass are primitives such as numbers or strings. The way to do it is to pass the name of the object then use the window object to gain access to your array object. Try this code
    PHP Code:
    function scrollDown(wndName,num,inc) {
        if (!
    pgLoaded) return;

        var 
    wndo window[wndName];
        var 
    parseInt(wndo[num].cnt.css.top);

        if (
    y>-wndo[num].maxY) { 
            
    wndo[num].cnt.shiftBy(0,-inc);
            
    scrTmId setTimeout("scrollDown('"+wndName+"',"+num+","+inc+")",scrTimer);
        }
    }
    function 
    scrollUp(wndName,num,inc) {
        if (!
    pgLoaded) return; 

        var 
    wndo window[wndName];
        var 
    scrollDiv wndo[num];
        var 
    parseInt(wndo[num].cnt.css.top);

        if (
    y<0) { 
            
    scrollDiv.cnt.shiftBy(0,inc);
            
    scrTmId setTimeout("scrollUp('"+wndName+"',"+num+","+inc+")",scrTimer);    
        }

    You then change the onmouseover to
    Code:
    onmouseover="scrollUp('gigs',0,4); 
    onmouseover="scrollDown('gigs',0,4);


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •