I have a function that automatically loads when the pages opens. I want the function to stop running after "onclick". I want the slideshow to stop running automatically after clicking a button.
<html>
<head>
<script type="text/javascript">
function changeImage(x){
imageNumber += x;
if(imageNumber > imageLength){
imageNumber = 0;
}
if(imageNumber < 0){
imageNumber = imageLength;
}
document.getElementById("slideshow").src = images[imageNumber];
document.getElementById("caption").innerHTML = caption[imageNumber];
return false;
}
function autoRun(){
//This function simply makes the slideshow change slides every 5 seconds.
setInterval("changeImage(1)", 5000);
}
function clearFunction(){
//This function needs to stop the autoRun function.
//If the user wants to manual flip through the slides,
//I don't want the slides to continue changing automatically
}
</script>
</head>
<body onload="autoRun()">
<a href="#" onclick="changeImage(-1); clearFunction();">Previous Slide</a>
<a href="#" onclick="changeImage(1); clearFunction();">Next Slide</a>
</body>
</html>