[thelist] Very basic JavaScript question

Shane Miller smiller at callcenters24x7.com
Thu Sep 30 04:52:03 CDT 2004


I don't know JavaScript.  The code pasted below is working well, so that
users can click a "next" button that calls the next() function and they
cycle through the images in the array.  What I'd like to do, though, is
"reset" back to the first picture when I've reached the last image in the
array.  I would like to hard code that, with an additional if-then statement
that if the index is four then change the index to zero, but I don't know
the syntax.

 

I'd sure be grateful if anyone could post some helpful suggestions!

 

Thanks,

 

Shane Miller

http://www.callcenters24x7.com

 


<SCRIPT LANGUAGE="JavaScript"><!--
var arrayOfImages = new Object();
 
var index = 0;
 
arrayOfImages[index++] = 'picture1.gif';
arrayOfImages[index++] = 'picture2.gif';
arrayOfImages[index++] = 'picture3.gif';
arrayOfImages[index++] = 'picture4.gif';
arrayOfImages[index++] = 'picture5.gif';
//--></SCRIPT>

 


<SCRIPT LANGUAGE="JavaScript"><!--
var start = 0;
 
function next() {
    if (document.images) {
        start++;
        if (start > index)
            start = index;
        else
            document.images['imageName'].src = arrayOfImages[start];
    }
}
 
//--></SCRIPT>

 



More information about the thelist mailing list