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 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Jul 2011
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    I'm sure there is a really simple solution to this ...

    but I just can't figure it out. I have trawled the net for a solution and tried many different things that I have seen but still no luck. Maybe the answer is staring me right in the face and I just can't see it.

    The code it executing the first time but as the setTimeout tries to start the second loop I get an error 'box is not defined'.

    Any suggestions and explanations of what I am doing wrong much appreciated!

    Code:
    function expand(box) {
    
    var box = document.getElementById(box);
    var originalHeight = parseInt(box.style.height);
    var inc = 5;
    
    newHeight = (originalHeight + inc);
    box.style.height = newHeight + "px";
    
    int = setTimeout('expand(box)',100); }

  • #2
    Banned
    Join Date
    Feb 2011
    Posts
    2,699
    Thanks
    13
    Thanked 395 Times in 395 Posts
    try

    Code:
    int = setTimeout(function(){expand(box);},100);

  • Users who have thanked bullant for this post:

    stevenmarsh (07-11-2011)

  • #3
    New to the CF scene
    Join Date
    Jul 2011
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thank you bullant. It has done something but not solved the problem. The error I am now getting is 'box is null' instead.

  • #4
    New to the CF scene
    Join Date
    Jul 2011
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    oops, just figured it out, pretty silly of me really. Thank you for pointing me in the right direction . This is how it had to be changed:

    Code:
    function expand(box) {
    
    var id = box;
    var box = document.getElementById(id);
    var originalHeight = parseInt(box.style.height);
    var inc = 5;
    
    newHeight = (originalHeight + inc);
    box.style.height = newHeight + "px";
    
    int = setTimeout(function(){expand(id);},100); }

  • #5
    Banned
    Join Date
    Feb 2011
    Posts
    2,699
    Thanks
    13
    Thanked 395 Times in 395 Posts
    ok, I've had a closer look.
    Code:
    var box = document.getElementById(box);
    The value of box, an id (string) of some value, being passed to the function the first time is being overwritten by the value of box (which is now an object reference) after it is passed to getElementById()

    Use a different variable name for the object reference to the element with the id = box.

  • #6
    New to the CF scene
    Join Date
    Jul 2011
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thank you

  • #7
    Banned
    Join Date
    Feb 2011
    Posts
    2,699
    Thanks
    13
    Thanked 395 Times in 395 Posts
    yep, no problem - good to see you sorted it out.

    The two variables in red need to have different names.

    Edit:
    looking at the time stamps, we are posting at near enough the same time ...lol
    Last edited by bullant; 07-11-2011 at 02:25 PM.


  •  

    Posting Permissions

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