4I'm currently working on a HTML code for a presentation that changes image based on a javascript array.
I managed to incorporate a looping code from a friend into my code, but I don't understand how to only make the image change once.
At the moment, it works that the javascript loops the items in the array to display different images, but I'd like it to work that it only changes once, based on a button click.
I'd like to keep my array if possible. Here's the code:
<html>
<head>
<script type='text/javascript'>
var banners = ["banner1.png", "banner2.png", "banner3.png"
"banner4.png"
];
var bnrCntr = 0;
var timer;
function banCycle() {
if (++bnrCntr == 4)
bnrCntr = 0;
timer = setTimeout("banCycle()", 4000);
}
function stopCycle() {
clearTimeout(timer);
}
</script>
</head>
<body>
<img src="bannerad1.png" name="banner" width=110 height=200>
<form>
<input type="button" value="Cycle" name="Cycle" onclick="banCycle()">
<input type="button" value="Stop" name="Stop" onclick="stopCycle()">
</form>
</body>
</html>
Thank you in advance!
EDIT- Just to clarify, I'm limited to pure javascript/HTML, and therefore I cannot use JSQuery.
timer = setTimeout("banCycle()",1000);?