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 8271549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T06:52:42+00:00 2026-06-08T06:52:42+00:00

SO I am trying to create a screen that will display about 50 toggle

  • 0

SO I am trying to create a screen that will display about 50 toggle buttons to display in a building on a monitor.

I want to create a bunch of images to use as the toggle so they are easy to see. This is the effect I want.
http://www.w3schools.com/dhtml/tryit.asp?filename=trydhtml_intro
except picture I want several light bulbs to turn on and off as I want.

Right now this is the code I have.
I am able to click the images to change as I want, they just wont go back, any ideas?

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01    
    Transitional//EN"  "http://www.w3.org/TR/html4/loose.dtd"> 
    <html> 
    <head> 
    <title>Untitled Document</title> 
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 
    <meta http-equiv="Content-Style-Type" content="text/css"> 
    <meta http-equiv="Content-Script-Type" content="text/javascript"> 
    <script type="text/javascript">
    function changeImg(img, newimg) {
    img.src = newimg;
    }


    </script>
    <body>
    <img onclick="changeImg(this, 'staten_uw.jpg')" src="staten_moored.jpg">
    <img onclick="changeImg(this, 'block_uw.jpg')" src="block_moored.jpg">
    </body>
    </html> 
  • 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-08T06:52:43+00:00Added an answer on June 8, 2026 at 6:52 am

    They don’t go back because the code always changes it to the _uw images. If you want them to toggle, the function needs to check what image is currently displayed. Something like this:

    function changeImg(img) {
        if ( img.src.indexOf("_uw") > 0 ) {
            img.src = img.src.replace("_uw","_moored");
        }
        else {
            img.src = img.src.replace("_moored","_uw");
        }
    }
    

    will work if you have 50×2 different images, named “img1_uw.jpg”, “img1_moored.jpg”, “img2_uw.jpg”, “img2_moored.jpg”, etc.

    If you only have 2 images, but want 50 buttons that each toggle between them, it’s easier:

    function changeImg(img) {
        if ( img.src == "staten_uw.jpg" ) {
            img.src = "staten_moored.jpg";
        }
        else {
            img.src = "staten_uw.jpg";
        }
    }
    

    Other answers have shown this quite simply as well.

    Either way, the HTML should change to something like this:

    <img onclick="changeImg(this)" src="block_moored.jpg">
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a shortcut on the home screen that, when pressed, will
I'm trying to create a Help/About screen for my application, but I've discovered that,
I'm trying to create an app that has a set of images on screen.
I'm trying to create a splash screen for MonoTouch, that fades from the Default.png
I'm trying to create a splash screen using LWUIT. I want a form to
I'm trying to use this to create a splash screen, but I only get
I'm trying to create a sitemap that will automatically update. I've done something similiar
I am trying to create a simple batch file that will replace a line
I'm trying to create a menu that will stick at the bottom of the
Im trying to create a PNG sequencer class that will allow me to change

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.