javascript next and previous buttons not working

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mle39920
    New Member
    • Oct 2013
    • 1

    javascript next and previous buttons not working

    I am having trouble executing the next and previous buttons on my page. The functions for nextBottonClick and previousButtonC lick specifically. Any help is greatly appreciated.

    Thansk


    Code:
    // Variable declarations.
    var imageCache = [];  // Array to hold the images from the invisible UL list.
    var imageItem = 0;    // Holds the currently displayed image index.
    var images = 0;       // Total images we have on the page to display.
    // Elements from the page we need to refer to.
    var captionNode;
    var imageNode;
    
    // Here is the $ function to simplify use of document.getElementById().
    var $ = function (id) { 
    	return document.getElementById(id); 
    }
    
    // Executed upon window load event.
    window.onload = function () {
        // Setting up various elements into variables to use later.
        var listNode = $("image_list");  
        var nextButton = $("next");
        var previousButton = $("previous");
        // Filling in the caption and image node variables.  
        captionNode = $("caption");
        imageNode = $("image");
    
        // The images are placed within <a> tags for convenience.  They aren't used as links ever.
        var links = listNode.getElementsByTagName("a");
        
        // Process image links.  A for loop is used to touch each of the images within the <a> tags
        // and store the image information into an array element.
        var i, linkNode, image;
        for ( i = 0; i < links.length; i++ ) {
            linkNode = links[i];
            // Pre-load image and copy title properties.
            image = new Image();
            image.src = linkNode.getAttribute("href");
            image.title = linkNode.getAttribute("title");
            imageCache.push(image);
        }
        // Now record the total images we have.
        images = imageCache.length;
        
        // Set up the button handlers.
        nextButton.onclick = nextButtonClick;
        previousButton.onclick = previousButtonClick;
    }
    
    function nextButtonClick() {
    	//TODO: Complete the next button click event handler to display the next image.
    	if(imageNode < images){
    		imageNode++
    	}
    	else{
    		imageNode = 1
    	}
    	document.slideImage.src = image[imageNode-1]
    	//      Roll the image over when we reach the end of the image set.
    	
    	// Increase image item index by 1;
    	
    	// Check to see if we are at the end of the image list.
    	// Remember, arrays are indexed starting a zero so if we have a number that is equal
    	// to the number of images, we have reached that point.
    	// If so, go back to the first image.
    	
    	
        // Now set the image src and title properties to the appropriate image.
        // To retrieve an image from imageCache with index imageItem, use imageCache[imageItem].
    }
    
    function previousButtonClick() {
        // Decrease image counter by 1.
    		if(imageNode > 1){
    		imageNode--
    	}
    	else{
    		imageNode = images
    	}
    	document.slideImage.src = image[imageNode-1]
    	
    
        // Check to see if we are less than zero.
        // If so, go to the last image.  Keep in mind that the index of the last
        // image is one less than the number of images.
    
        // Now set the image src and title properties to the appropriate image.
        
    }
Working...