Thread: Baffled

    #1
  1. No Profile Picture
    Cherie
    Guest
    Devshed Newbie (0 - 499 posts)
    Okay webmasters, please put your wizard hats on and work your magic.

    I have a great little slide show that I am working on. I just about have
    it done, but I have a problem that is driving me nuts!!!

    The problem is my "back" button. Once the back button hits the first
    image and the user clicks back again, a javascript error occurs (it
    states: That my variable is not defined). I know that it is defined
    otherwise the back button would not work at all. The "next" button does
    not have this problem it will loop continously. I have been researching
    others slideshows and a lot of them use seperate html pages or have an
    alert appear when the user tries to go past the first image.

    Here's the code: Note** imageDB is the array for all the images.

    function next() {
    if (boardNum < imageDB.length - 1) boardNum++;
    else boardNum = 0;
    document.selections.cached.selectedIndex = boardNum
    document.thumbnail1.src = imageDB[boardNum].src
    boardSpeed=6000;
    }

    function back() {
    if (boardNum < imageDB.length - 1) boardNum--;
    else boardNum = 0;

    document.selections.cached.selectedIndex = boardNum
    document.thumbnail1.src = imageDB[boardNum].src
    boardSpeed=6000;
    }

    // This is the function for rotation of images, call for this in the body<tag> onload
    function rotateBoard() {
    if (boardNum < imageDB.length - 1) boardNum++;

    else boardNum = 0;
    document.selections.cached.selectedIndex = boardNum
    document.thumbnail1.src = imageDB[boardNum].src
    setTimeout('rotateBoard()', boardSpeed);
    }

    My goal is for the back button to jump back on image 1 and go to the
    last image and then continue to count down from there.

    I have tried using an if statement, it removed the error but the back
    button would only go to the first image and that was it.

    Also, would you happen to know of a good reliable tool for compiling
    javascript in. A watch/debugger utility, where I can run a script and
    watch how it plays out with the variables and functions.

    I thank you in advance for any help...
    Cherie
  2. #2
  3. No Profile Picture
    giorgios
    Guest
    Devshed Newbie (0 - 499 posts)
    Try using the onUnload object for when leaving a document. Make it write boardnum to a variable called back(or something similar).
    Have function back call on this variable instead.
    This method will only go back once unless you can figure out some way to use an array to create a history.

    Sorry I can't give you more details but I'm a beginner still.

    I hope I've been of some help.

    ------------------
    If our time is up, what is down?
  4. #3
  5. No Profile Picture
    Cherie
    Guest
    Devshed Newbie (0 - 499 posts)
    Thank you for your response.

    I am using an array to control the images that swap. It is imageDB. Then boardNum (which calls to the same array imageDB) is used to control the back and next buttons in a function.

    I have researched the web looking for slideshows that swap images(not pages) in the same page and have next and back buttons, I noticed that none of them let you go back past the first image. I know I am not alone in this quest...
  6. #4
  7. No Profile Picture
    tkessler
    Guest
    Devshed Newbie (0 - 499 posts)
    The if statment in your back function that looks like this:

    if (boardNum < imageDB.length - 1)
    boardNum--;
    else
    boardNum = 0;


    Should probably look like this

    if (boardNum > 0)
    boardNum--;
    else
    boardNum = imageDB.length-1;


    The first version would allow the boardNum to become negative, causing an error, the second one will return the boardNum index to the end of the array.

  8. #5
  9. No Profile Picture
    Cherie
    Guest
    Devshed Newbie (0 - 499 posts)
    tkessler,

    Hat's off to you!!!

    Thank you so much! I hope someday,somehow I will be able to return the favor.

    Thank's again,
    Cherie

Similar Threads

  1. Replies: 0
    Last Post: January 10th, 2004, 06:15 PM
  2. Baffled - using javascript active X
    By gav567 in forum JavaScript Development
    Replies: 0
    Last Post: November 9th, 2003, 06:39 PM
  3. Terminal Update problems.....
    By Chris Hall001 in forum ASP Programming
    Replies: 16
    Last Post: August 9th, 2003, 05:24 AM
  4. Unique Calendar Problem TOTALLY BAFFLED
    By boblangdon in forum PHP Development
    Replies: 5
    Last Post: April 30th, 2002, 11:26 PM
  5. Form Processing "Error in Epression" has be baffled
    By G2Koolio in forum Perl Programming
    Replies: 0
    Last Post: March 5th, 2002, 05:30 AM

IMN logo majestic logo threadwatch logo seochat tools logo