Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-01-2006, 03:53 PM   PM User | #1
lilqhgal
New Coder

 
Join Date: Aug 2005
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
lilqhgal is an unknown quantity at this point
Image browsing script skips first 4, but ok on way back...

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:

Javascript:
Code:
<!-- 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]
		i--
	}
}

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

// -- End Hiding Here -->

HTML:
Code:
<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!
lilqhgal is offline   Reply With Quote
Old 11-01-2006, 04:37 PM   PM User | #2
lilqhgal
New Coder

 
Join Date: Aug 2005
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
lilqhgal is an unknown quantity at this point
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....

Ramsey
lilqhgal is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:56 PM.


Advertisement
Log in to turn off these ads.