/    Sign up×
Community /Pin to ProfileBookmark

Stumped on previous/next javascript code…

Hi all,
I have an iFrame that will eventually have a set of images that you can scroll through using a previous and next button below them. Right now there are only two images. I had the next/previous javascript working when I had four placeholders, but now the client only wants two images up and when you are on the second image and hit next, it goes to a blank screen.

I’m assuming it’s something really simple that I am not doing so any help on this would be so much appreciated.

here’s the iFrame of the images: [url]http://www.brodmannblades.com/product.html[/url]

[code=html]<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<script type=”text/javascript” src=”nextPrevious.js”></script>
<meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8″ />
<title>Untitled Document</title>
<style type=”text/css”>
<!–
body {
background-color: #000000;

}
body,td,th {
color: #333;
}
a:link {
color: #333;
text-decoration: none;
}
a:visited {
color: #666;
text-decoration: none;
}
a:hover {
color: #09C;
text-decoration: none;
}
a:active {
color: #000;
text-decoration: none;
}
–>
</style>

</head>

<body>
<div style=”width:780px; height:400px; margin: auto;”>
<img name=”imgSrc” width=”780″ height=”400″ id=”imgSrc”>
</div>

<!– Controller –>
<table width=”780″ border=”0″ cellspacing=”0″ cellpadding=”0″ style=”border:1px solid #000000; width:780px; margin: auto;”>
<tr>
<td align=”center”><a href=”#” onClick=”prev();”> «</a></td>
<td align=”center”><a href=”#” onClick=”next();”> » </a></td>
</tr>
</table>
<p>
</body>

</html>[/code]

and here’s the javascript code that it is calling up: [url]http://www.brodmannblades.com/nextPrevious.js[/url]

[CODE]// List image names without extension
var myImg= new Array(2)
myImg[0]= “bw01”;
myImg[1]= “bw02”;

// Tell browser where to find the image
myImgSrc = “images/”;

// Tell browser the type of file
myImgEnd = “.jpg”

var i = 0;

// Create function to load image
function loadImg(){
document.imgSrc.src = myImgSrc + myImg[i] + myImgEnd;
}

// Create link function to switch image backward
function prev(){
if(i<1){
var l = i
} else {
var l = i-=1;
}
document.imgSrc.src = myImgSrc + myImg[l] + myImgEnd;
}

// Create link function to switch image forward
function next(){
if(i>2){
var l = i
} else {
var l = i+=1;
}
document.imgSrc.src = myImgSrc + myImg[l] + myImgEnd;
}

// Load function after page loads
window.onload=loadImg;[/CODE]

Again, thanks for any help!

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@NedalsMay 05.2009 — <i>
</i>var i;
function prev(){
(i&gt;1) ? i-- : i=1;
document.imgSrc.src = myImgSrc + myImg[i] + myImgEnd;
}
function next(){
(i&lt;2) ? i++ : (i==2) ? i=0 : i=2; // where myImg[0] is a blank image (transparant pixel)
document.imgSrc.src = myImgSrc + myImg[i] + myImgEnd;
}
Copy linkTweet thisAlerts:
@slickshoes12authorMay 05.2009 — thanks!

that worked for clearing up the blank undefined image at the end of the image sequence but now i have a broken link when i click into the product page to start the image sequence.

here's the site:

http://www.brodmannblades.com

click the products tab and you'll see what i mean.
×

Success!

Help @slickshoes12 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.27,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...