Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8926455
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:58:36+00:00 2026-06-15T07:58:36+00:00

I am trying to construct a thumbnail slideshow with javascript. I am very new

  • 0

I am trying to construct a thumbnail slideshow with javascript. I am very new to Javascript so my way of doing it might be a little strange…

The problem I am running into is that I have a main image, and then I have 4 thumbnails. When I click on the first thumbnail it changes the main image, and the first thumbnail. But when I click on the changed thumbnail it needs to change the main image with a different photo (the one that corresponds to the new thumbnail)

I initialize my functions with a call like this:

document.getElementById('thumb1').onclick=thumbs1;

Which uses this function:

function thumbs1(){
    num1 = 1;
    num2 = 0;
    var src1 = largeArray[num1];
    var src2 = thumbArray[num2];
    document.getElementById('main').src=src1;
    document.getElementById('one').src=src2;
    document.getElementById('one').id='change';
}

And I am trying to change the id of the new thumbnail to “change” and call another function like this:

document.getElementById('change').onclick=changed;

And this used the following function:

function changed(){
    num1 = 0;
    var src1 = largeArray[num1];
    document.getElementById('change').src=src1;
    document.getElementById('change').id='one';
}

When using Firebug I found the error, and I believe it is being caused by the fact that the call to document.getElementById('change').onclick=changed;. The browser can not find the Element Id “change” because I have not called the function which changed the ID yet.

Does anyone know how to fix this problem. (I know the code is of low quality… I am teaching my self)

Here is a live link to the page: My Page

Thanks for any help!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T07:58:37+00:00Added an answer on June 15, 2026 at 7:58 am
    var array = //id's of your images here. you could type them static or search your document for images and get their id attribute.
    
    document.addEventListener("click", function(e){
        var clicked_image = e.target || e.srcElement; //using jquery can help with this cause older versions of IE are stupid, but depends on if you want to support them. 
        var id = clicked_image.getAttribute(id);
        var temp = document.getElementById("main").src;
    
        for (var i = 0; i < array.length; i++){
            if(array[i] == id){
                document.getElementById("main").src = clicked_image.src;
                clicked_image.src = temp;
            }
        }
    })
    

    That’s pretty quick and dirty, you would be better off assigning eventlisteners to just your images. You would use the same syntax as above, but it should give you an idea of what to do.

    With this you don’t have to worry about what image got clicked, you just change the main, and you change the thumb to what the main was. So you eliminate the hassle of trying to keep track of what each image is.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to construct a HTML table in python and running into the
I am trying to construct a way to keep certain hard drive partitions/usb drives
I'm trying to construct a table with Prototype's New Element function. I was experiencing
I am trying to construct my first new action in rails, thanks to the
I'm trying to construct a little mobile optimized web. This web list a set
I am trying to construct an m-way tree and I am having trouble visualizing
I'm trying to construct a javascript array from a db query. Each item in
I'm trying to construct a simple status panel using MigLayout as follows: setLayout(new MigLayout(fillx,
I'm trying to construct a String in JS that can be passed into JSON
Trying to construct a Request with Network.HTTP.Conduit package. The instructions are: The constructor for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.