Check this fiddle out, it is exactly your code and it just works to me..
This is probably a browser
specific problem..
Question
created this simple image array gallery
javascript function call not looping the image array
var imagecount=0;
var imageArray = ["images/1.jpg","images/2.jpg","images/3.jpg","images/4.jpg"];
var allimages=imageArray.length-1;
function next()
{
imagecount++;
if(imagecount>allimages) {
imagecount=0;
}
document.getElementById("slideshow").src=imageArray[imagecount];
}
function prev()
{
imagecount--;
if(imagecount<0) {
imagecount=allimages;
}
document.getElementById("slideshow").src=imageArray[imagecount];
}
document.getElementById("next").onclick=next;
document.getElementById("previous").onclick=prev;
as i am calling the function in javascript itself the image gallery is not looping
Solution
Check this fiddle out, it is exactly your code and it just works to me..
This is probably a browser
specific problem..
OTHER TIPS
You are mostly likely exceeding the array bounds. Change:
if(imagecount>allimages){
to
if(imagecount>allimages-1){