473,378 Members | 1,146 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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 previousButtonClick specifically. Any help is greatly appreciated.

Thansk


Expand|Select|Wrap|Line Numbers
  1. // Variable declarations.
  2. var imageCache = [];  // Array to hold the images from the invisible UL list.
  3. var imageItem = 0;    // Holds the currently displayed image index.
  4. var images = 0;       // Total images we have on the page to display.
  5. // Elements from the page we need to refer to.
  6. var captionNode;
  7. var imageNode;
  8.  
  9. // Here is the $ function to simplify use of document.getElementById().
  10. var $ = function (id) { 
  11.     return document.getElementById(id); 
  12. }
  13.  
  14. // Executed upon window load event.
  15. window.onload = function () {
  16.     // Setting up various elements into variables to use later.
  17.     var listNode = $("image_list");  
  18.     var nextButton = $("next");
  19.     var previousButton = $("previous");
  20.     // Filling in the caption and image node variables.  
  21.     captionNode = $("caption");
  22.     imageNode = $("image");
  23.  
  24.     // The images are placed within <a> tags for convenience.  They aren't used as links ever.
  25.     var links = listNode.getElementsByTagName("a");
  26.  
  27.     // Process image links.  A for loop is used to touch each of the images within the <a> tags
  28.     // and store the image information into an array element.
  29.     var i, linkNode, image;
  30.     for ( i = 0; i < links.length; i++ ) {
  31.         linkNode = links[i];
  32.         // Pre-load image and copy title properties.
  33.         image = new Image();
  34.         image.src = linkNode.getAttribute("href");
  35.         image.title = linkNode.getAttribute("title");
  36.         imageCache.push(image);
  37.     }
  38.     // Now record the total images we have.
  39.     images = imageCache.length;
  40.  
  41.     // Set up the button handlers.
  42.     nextButton.onclick = nextButtonClick;
  43.     previousButton.onclick = previousButtonClick;
  44. }
  45.  
  46. function nextButtonClick() {
  47.     //TODO: Complete the next button click event handler to display the next image.
  48.     if(imageNode < images){
  49.         imageNode++
  50.     }
  51.     else{
  52.         imageNode = 1
  53.     }
  54.     document.slideImage.src = image[imageNode-1]
  55.     //      Roll the image over when we reach the end of the image set.
  56.  
  57.     // Increase image item index by 1;
  58.  
  59.     // Check to see if we are at the end of the image list.
  60.     // Remember, arrays are indexed starting a zero so if we have a number that is equal
  61.     // to the number of images, we have reached that point.
  62.     // If so, go back to the first image.
  63.  
  64.  
  65.     // Now set the image src and title properties to the appropriate image.
  66.     // To retrieve an image from imageCache with index imageItem, use imageCache[imageItem].
  67. }
  68.  
  69. function previousButtonClick() {
  70.     // Decrease image counter by 1.
  71.         if(imageNode > 1){
  72.         imageNode--
  73.     }
  74.     else{
  75.         imageNode = images
  76.     }
  77.     document.slideImage.src = image[imageNode-1]
  78.  
  79.  
  80.     // Check to see if we are less than zero.
  81.     // If so, go to the last image.  Keep in mind that the index of the last
  82.     // image is one less than the number of images.
  83.  
  84.     // Now set the image src and title properties to the appropriate image.
  85.  
  86. }
  87.  
Oct 19 '13 #1
0 1286

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Marcel | last post by:
Hello, I'm working on a search application for my website. The website contains a lot of pictures, and a search should return clickable thumbnails. No problems there. My problem started when I...
9
by: Karl Roes | last post by:
Hi All, I would like some advice on Next / Previous record buttons. I have a main form for the client, and a continuous subform listing client transactions. If I open one of these transactions...
1
by: msnews | last post by:
Hi All, My client has following request. I am not sure how to do it. Dynamically from database, we are getting set of images names. Now we want to display them with next and previous buttons....
1
by: David | last post by:
What I envision is this. The user gets a set of records in a data grid Then the user gets to select one of the rows to view the detail information about the record. Then instead of backing...
0
by: Roger23 | last post by:
I am trying to use a wizard for a mulit-process step where i have to navigate to different screens. The user can see that in two modes, read-only and update. when its read-only i want to hide the...
1
by: Reb | last post by:
Hi all, I have not successfully found a Javascript sample for getting next and previous links from a file... I figured that someone must have solved this problem already! ... here is what I'm...
1
by: shapper | last post by:
Hello, Is it possible to use images as Next / Previous buttons on an Asp.Net 2.0 GridView? Thanks, Miguel
8
by: GaryDean | last post by:
I have a Wizard page and need to affect the next and previous buttons from my code-behind. I've googled around and found two solutions, and neither appear to work. I can access the SideBarList...
1
by: mfaisalwarraich | last post by:
hi everybody, im trying to make next and previous buttons. im displaying record based on a search. when any image on the search results is clicked then dat image opened in a new page with details...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.