Forum Moderators: open

Message Too Old, No Replies

setInterval stop and reset problem

setInterval reset doing strange things

         

mindenmedic

8:14 pm on Feb 11, 2008 (gmt 0)

10+ Year Member



i am trying to stop a timer on mouseover and restart it on mouseout. it works fine on mouseover but on mouseout it shows to count by 2s

// initialize

var timerval;
var c=0;
timerval = setInterval("timedCount()",1000);

function timedCount()
{
document.getElementById('txt').value =c;
c=c+1;
if (c == 1){ requesthx('../callhx.php'); }
if (c == 2){ requesthx('../dispmessages.php'); }
if (c == 4){ requesthx('../getnames.php'); }
if (c == 5){ requesthx('../topbars.php'); }
if (c == 6){ requesthx('../showroads.php'); }
if (c >= 7){ c=0;}
}
//on mouseover
function timeroff(){
clearInterval(timerval);
document.getElementById('txt').value =0;
c=0;
}

// on mouseout
function timeron(){
timerval = setInterval("timedCount()",1000);

}

watching the 'txt' field at first it reads 1,2,3,4,5 ect...
then mouseover reads 0
then mouseout reads 1,3,5,7 ect...
?

any help anyone?

mehh

8:55 pm on Feb 11, 2008 (gmt 0)

10+ Year Member



I think the mouseout event is fireing twice. I don't know why it would be doing that but try this:
function timeron(){ 
clearInterval(timerval);
timerval = setInterval("timedCount()",1000);
}

mindenmedic

9:06 pm on Feb 11, 2008 (gmt 0)

10+ Year Member



sweet... it works great, thanks