View Full Version : Image browsing script skips first 4, but ok on way back...

11-01-2006, 04:53 PM
I have a small script that has a forward and back button next to an image. On clicking the forward button, it rotates through the available images in the array. However, I've noticed that when you click the first time the page loads, the script skips ahead to the 3rd image in the array. Then, if you click the back button, it will go back thru #3, #2 and then to #1 just fine, and THEN it will progress correctly from there once you click the forward button again.

Here is the page: http://biology.wright.edu/newsite/

Here is the code snippets:


<!-- Hide from old browsers
// Copyright 1999 Doug Popeney
// Created by Doug Popeney (easyjava@easyjavascipt.com)
// JavaScript Made Easy!! - http://www.easyjavascript.com

var i = 1
images = new Array
images[1] = "images/gallery-frontpage/gallery-frontpage1.gif"
images[2] = "images/gallery-frontpage/gallery-frontpage2.gif"
images[3] = "images/gallery-frontpage/gallery-frontpage3.gif"
images[4] = "images/gallery-frontpage/gallery-frontpage4.gif"
images[5] = "images/gallery-frontpage/gallery-frontpage5.gif"
images[6] = "images/gallery-frontpage/gallery-frontpage6.gif"
images[7] = "images/gallery-frontpage/gallery-frontpage7.gif"
images[8] = "images/gallery-frontpage/gallery-frontpage8.gif"

function previmg(){
if (i != 1){
document.image1.src = images[i-1]

function nextimg(){
if (i != 8){
document.image1.src = images[i+1]

// -- End Hiding Here -->


<img src="images/gallery-frontpage/gallery-frontpage1.gif" alt="Biology Photo Gallery Preview" name="image1" width="343" height="290" />
<a id="left" href="" onClick="previmg();return false;">previous image</a>
<a id="right" href="" onClick="nextimg(); return false;">next image</a>

What have I done wrong? I'm sure it's simple... but... forest for the trees here. Thanks!

11-01-2006, 05:37 PM
Also, I forgot to mention... Is there any way to have the script jump back to the first image once the user has clicked all the way to the last image? Currently, you hit the last one, click again, and nothing happens. I'd like it to sort of "loop" or never end if possible. If not, no biggie. Thanks....