clearInterval Issue

Hi All,

I’m having an issue with intervals in javascript. It seems that although i’m calling the clearInterval functions at the right time, the intervals aren’t clearing.


<script>

var e = document.getElementById('pagecontent');
e.style.position = "relative";
var frame = 0;
var counter = 0;
var lastIntS = "";
var nextIntS = "";
function nextPage() {
if(counter > -400){
e.style.scrollTop = (counter - 20) + "px" ;
counter = (counter - 20);
}else{
window.clearInterval(nextIntervalS);
}
}

function lastPage() {
if(counter <= 0){
e.style.top = (counter + 20) + "px" ;
counter = (counter + 20);
}else{
window.clearInterval(lastIntS);
}
}
 
function lastInt(){
var lastIntS = setInterval("lastPage();", 100);
}
function nextInt(){
var nextIntS = setInterval("nextPage();", 100);
}
</script>
<div style="width:150px; float:left;"><a class="pagebtn" onMouseUp="setTimeout('clearInterval(lastIntS)', 2000)" onMouseDown="lastInt();">Previous Page</a></div><div style="width:150px; float:right;"><a class="pagebtn" onMouseUp="setTimeout('clearInterval(nextIntS)', 5000)" onMouseDown="nextInt();">Next Page</a></div>
 

In the code above i actually tried clearing the interval with a setTimeout script on mouse up and that didn’t work either. I’ve tried several different ways so any help would be greatly appreciated.

Thanks,
Mat