Jump to content

[SOLVED] complecated(?) timer


taith

Recommended Posts

i need to get this counter working... might be a compecated way of doing it... but thats the way it needs to be...

 

<script>
var counters=new Array();



function spankind(){

var x=document.getElementsByTagName("span");
for(var i=0; i<x.length; i++){

  var kind=x[i].getAttribute("kind");

  if(!kind) continue;
  switch(kind){

   case "counter":
    counters[i]=counter(x[i],i);

   break;

  }

}
}

function counter(el,id){
var val=el.innerHTML;
if(isNaN(val)) val=0;
val++;
el.innerHTML=val;
setTimeout("counter(el)",1000);
}

function init(){
spankind();
}

window.onload=init;
</script>
<span kind=counter></span>

 

i keep getting errors on this line "setTimeout("counter(el)",1000);"

saying that el is undefined... but its not...?

 

anyone got a clue whats goin on there? :D

Link to comment
https://forums.phpfreaks.com/topic/85974-solved-complecated-timer/
Share on other sites

ok... getting there...

 

<script>
var counters=new Array();



function spankind(){

var x=document.getElementsByTagName("span");
for(var i=0; i<x.length; i++){

  var kind=x[i].getAttribute("kind");

  if(!kind) continue;
  switch(kind){

   case "counter":
    counters[i]=setInterval(counter(x[i]),1000);

   break;

  }

}
}

function counter(el){
var val=el.innerHTML;
if(isNaN(val)) val=0;
val++;
el.innerHTML=val;
}

function init(){
spankind();
}

window.onload=init;
</script>
<span kind=counter></span>

 

sofar... it counts to 1... and not beyond :-( i'm getting "invalid argument"... line 11 char 5

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.