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

  • Home
  • SEARCH
  • 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 8759449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:48:35+00:00 2026-06-13T14:48:35+00:00

Now, I’m new to web programming, javascript in particular. I’m trying to write a

  • 0

Now, I’m new to web programming, javascript in particular. I’m trying to write a script that will update the image on a webpage and its text when the user clicks the image. Here’s the code:

//Images array
imgs = Array("test1.jpg", "test2.jpg", "test3.jpg");

//Names array
names = Array("Test1", "Test2", "Test3");

//Holds how many times our page has been clicked
var click = 0;

//Another click var
var click2 = 0;

//change function 
function change()
{

//Get the ID of 'nam', and start incrementing the elements in our array
document.getElementById("nam").innerHTML = names[++click2];

//Get an element with the ID 'first', and start incrementing the elements in  our      array
document.getElementById("first").src = imgs[++click];

//If the user clicks to the end of the gallery
if(click==2)
{
    click = -1;
}

if(click2==2)
{
    click = -1;
}

}

Probably not the best way to do this, but this code will work at first. However, when I click the third image to go back to the first, the pictures work fine, but the text becomes ‘undefined’. I’ve searched around, but I can’t seem to find anything really ‘wrong’ with this code.

Any help is appreciated.

  • 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-13T14:48:37+00:00Added an answer on June 13, 2026 at 2:48 pm

    Typo in var name:

    //If the user clicks to the end of the gallery
    if(click==2)
    {
        click = -1;
    }
    
    if(click2==2)
    {
        click = -1;
    }
    

    should be

    //If the user clicks to the end of the gallery
    if(click==2)
    {
        click = -1;
    }
    
    if(click2==2)
    {
        click2 = -1;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Now I try to developing an application related to Image processing, for that I
Now I am exceptionally new to network programming so tell me if this is
Now that I've upgraded to Rails 3, I'm trying to figure out the proper
now that my orbit slider works almost perfect, i discovered a new problem. I'm
Now, that we have new iPhone 5 and iPad 3, what resolution of design
now i'm working on a project for creating audio unit instrument that provide the
Now getting error Webpage error details User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT
Now I'm trying to display the result of consuming a webservice from one page
Now I'm trying some tests to erase the actual touch to beam in NFC
Now that it is possible to make non-container-bound webapps, it would make sense to

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.