...

View Full Version : beginner- onClick="prev();" onClick="next();"



rtareva
06-06-2008, 11:40 PM
Here is a simple slideshow http://www.rumenvasilev.com/photography/nature/index.php using <a href="#" onClick="prev();"> «</a>&nbsp;&nbsp;&nbsp;<a href="#" onClick="next();"> » </a>

Images load to the fourth one then stop. Can’t see what’s the problem I am sure it is silly. Any ideas?
Here is the code:

// Lists image names without extension var myImg= new Array(3)
myImg[0]= "01";
myImg[1]= "02";
myImg[2]= "03";
myImg[3]= "04";
myImg[4]= "05";
myImg[5]= "06";
myImg[6]= "07";
myImg[7]= "08";
myImg[8]= "09";
myImg[9]= "10";


// Tells browser where to find the imagemyImgSrc = "/photography/nature/";

// Tells browser the type of file myImgEnd = ".jpg"

var i = 0;

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

// Creates 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;
}

// Creates 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;
}

// Loads function after page loads window.onload=loadImg;



TNX for your time

gnomeontherun
06-06-2008, 11:52 PM
var myImg= new Array(3)
If this is actually on its own line, then take the number out. I think that could be a problem.

rtareva
06-07-2008, 12:08 AM
still does not work using
var myImg= new Array()
tried var myImg= new Array(10)
does not work either:))

rtareva
06-07-2008, 12:25 AM
ok found the answer:
http://www.webmasterworld.com/new_web_development/3617994.htm
---------------------------------
// 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;
}
The red number needs to be 1 less than last index used here

myImg[3]= "pix4";
---------------------------------

tnx for your help



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum