You are here: irt.org | FAQ | JavaScript | Image | Q754 [ previous next ]
It depends what you mean by an array of images. If you mean something like:
<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>
Then you can use:
<SCRIPT LANGUAGE="JavaScript"><!-- var start = 0; function next() { if (document.images) { start++; if (start > index) start = index; else document.images['imageName'].src = arrayOfImages[start]; } } function last() { if (document.images) { start--; if (start < 0) start = index; else document.images['imageName'].src = arrayOfImages[start]; } } //--></SCRIPT>