It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming JavaScript Forum

JS next and prev code HELP

JS next and prev code HELP

Postby freebirdnz on Tue Oct 09, 2007 3:59 pm

Hi there,

I am new to JS and am trying to tweak this code to show a range of images. As you can see I have named the images from 1-50. (although I haven't finished)

Is there a way I can add each image in the function rather then copying the function for each image? The way I have copied it, as soon as it hits the 2nd image it will only add the next image. Do I have to copy the function again and again or can I add all images in the function.

I will need someone to give me the code if possible as I am only new to JS. Thank you.



Code: Select all
/* This script and many more are available free online at
The JavaScript Source :: http://javascript.internet.com
Created by: Solomon, the Sleuth :: http://www.freewebs.com/thesleuth/scripts/ */

// List image names without extension
var myImg= new Array(50)
  myImg[0]= "1";
  myImg[1]= "2";
  myImg[2]= "3";
  myImg[3]= "5";
  myImg[4]= "6";
  myImg[5]= "7";
  myImg[6]= "8";
  myImg[7]= "9";
  myImg[8]= "10";
  myImg[9]= "11";
  myImg[10]= "12";
  myImg[11]= "13";
  myImg[12]= "14";
  myImg[13]= "";
  myImg[14]= "";
  myImg[15]= "";
  myImg[16]= "";
  myImg[17]= "";
  myImg[18]= "";
  myImg[19]= "";
  myImg[20]= "";
  myImg[21]= "";
  myImg[22]= "";
  myImg[23]= "";
  myImg[24]= "";
  myImg[25]= "";
  myImg[26]= "";
  myImg[27]= "";
  myImg[28]= "";
  myImg[29]= "";
  myImg[30]= "";
  myImg[31]= "";
  myImg[32]= "";
  myImg[33]= "";
  myImg[34]= "";
  myImg[35]= "";
  myImg[36]= "";
  myImg[37]= "";
  myImg[38]= "";
  myImg[39]= "";
  myImg[40]= "";
  myImg[41]= "";
  myImg[42]= "";
  myImg[43]= "";
  myImg[44]= "";
  myImg[45]= "";
  myImg[46]= "";
  myImg[47]= "";
  myImg[48]= "";
  myImg[49]= "";
  myImg[50]= "";

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

// Tell browser the type of file
myImgEnd = ".gif"

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;[b]
[/b]
freebirdnz
 
Posts: 2
Joined: Tue Oct 09, 2007 3:51 pm

Postby bobbyblades on Wed Oct 10, 2007 7:17 am

what are you attempting to do? the function is called and shows the first image on the page load what do you want to happen after that?
User avatar
bobbyblades
50+ Club
 
Posts: 85
Joined: Fri Aug 24, 2007 8:38 pm
Location: hawaii or bust

Postby freebirdnz on Wed Oct 10, 2007 8:37 am

Hi,

It's a gallary...it gets to the 2nd image then stops but I worked it out as totally missed if(i>2){

I changed this to how many photos there are and it works.

Thanks for your reply.

Freebird
freebirdnz
 
Posts: 2
Joined: Tue Oct 09, 2007 3:51 pm


Who is online

Users browsing this forum: No registered users and 2 guests