Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jun 2008
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy beginner- onClick="prev();" onClick="next();"

    Here is a simple slideshow http://www.rumenvasilev.com/photogra...ture/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

  • #2
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    Code:
    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.

  • #3
    New to the CF scene
    Join Date
    Jun 2008
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    still does not work using
    var myImg= new Array()
    tried var myImg= new Array(10)
    does not work either)

  • #4
    New to the CF scene
    Join Date
    Jun 2008
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ok found the answer:
    http://www.webmasterworld.com/new_we...nt/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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •