If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

setTimeout issue

i'm running out of memmory at line 23, or the function
executes only once, (even if i call it several times), so
there isprobably a bug in the function causing the script
to halt.

javascript was the first language i learned years back,
and i've been coding php mostly since, so i might have
the wrong syntax.

all i'm trying to do is call goLeft(), and have it call itself
several times using setTimeOut() until the variable left is
no longer less than 50. which should animate the box
by moving it to the right 5px every 500milliseconds.

it's probably a very simple fix but i just can't recall.

help me out please.

lol, i know i can use jquery animate, but i'm doing a
live javascript course and learning to manually manipulate
the dom without using jquery.

it worked fine before encapsulating the code into a function
and just using setInterval(), so i dunno what went wrong.

should i call the function from within itself, or just in the body
of the page? or should i just call setTimeOut(goLeft(),500) once
outside of the function?

it should call itself recursively a couple times as it makes the
box move across the screen every half second.

i'm either getting the memory error or it only calls itself once
and terminates. i understand what your hinting at, but not
sure how to code it to work, can you adjust my code so
i can see what i'm still doing wrong?

lol

Originally Posted by Padonak

it is really strange to hear that this code works while you have this line

box.style.left=left;//+'px';

in it

lol it works with or without it, but then again i'm only using IE at the moment, i actually expected it only to work when i the script adds the pixels, but it works without it at least in IE, i'll remove the comment so it will be proper i just kinda forgot since it was working, lol.

i'd normally just use jquery animate() but i'm learning event handling and dom scripting via a live course at the moment so i'm avoiding jquery in order to learn the manual way.