Forum Moderators: open
var slideTimer;function enableSlideMode () {
slideMode = Boolean(true);
slideTimer = setTimeout('showNext();', (slideDelay * 1000));
}function disableSlideMode() {
slideMode = Boolean(false);
clearTimeout (slideTimer);
}
It seems like this could be an issue of scope where it thinks slideTimer is a local variable within enableSlideMode(). However, I start the script with a global declaration of "var slideTimer;". Do I need to do something else to make it truly global?
<SCRIPT>
var slideTimer;
function enableSlideMode () {
slideMode = Boolean(true);
slideTimer = setTimeout('showNext();', (1000));
alert(slideTimer);
}
function disableSlideMode() {
slideMode = Boolean(false);
clearTimeout (slideTimer);
}
function showNext(){alert('next Slide');slideTimer = setTimeout('showNext();', (1000)); }
</SCRIPT>
<body onload=enableSlideMode()>
<INPUT type=submit onclick=disableSlideMode() value=stop>
</body>
Maybes other parts of your script are misbehaving, which is causing the clearTimeout not to function as you intend.
Rem, that setTimeout is a one-time timer. setInterval can be used for repeated calls.