Hey everyone i'm new to the community, hello
The function discussed in this thread is at the bottom of this post.
What this function does is countdown the value of an HTML table-cell to zero (minus 1 every second) then stop counting that specific cell when it's finished. This works perfectly, the problem is that when it is called AGAIN for a different table-cell, the previous cell starts reducing its value by 2 every second instead of 1. This function supports the Hour:Minute:Second format.
So, how would i make this function so that i can call an infinite number of different table cells, and the previous table cells timers would not be affected (they would still countdown 1 per second as they should)?
Thank you so much. I have been stuck on this problem for 2 weeks and just left my project dormant because of it. This simple problem has struck me from behind and destroyed my passion for the project - please help me get back on track!
-Ollie
This is the code which CALLS the function, where $i is 1-5 inclusive, defined by PHP:
Code:timer('ff".$i."', ". rand(1,100) .");
This is the BODY of the function itself, called by the above command
Code:var running = new Array(50); function timer(data, id) { //clearTimeout(id[data]); var id=new Array(50); // usage: var id=new Array(50); timer('cq0'); dat=document.getElementById(data); var time=(dat.innerHTML).split(":"); var done=0; if(dat.innerHTML == null) { done = 1; alert('null'); } if (time[2]>0) time[2]--; else { time[2]=59; if (time[1]>0) time[1]--; else { time[1]=59; if (time[0]>0) time[0]--; else { clearTimeout(id[data]); done=1; running[data] = 0; renderStack(); } } } if (!done) { dat.innerHTML=time[0]+":"+time[1]+":"+time[2]; id[data]=setTimeout("timer('"+data+"')", 1000); running[data] = 1; } }




Reply With Quote

Bookmarks