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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:30:37+00:00 2026-06-17T04:30:37+00:00

This one is a real headache. I have three checkboxes in a form that

  • 0

This one is a real headache. I have three checkboxes in a form that I have labels for, and the labels have background images set with CSS, the question is, how exactly do I get my JavaScript to change the image from current image to a second image when it is clicked and select the checkbox. From what I know of javascript, it should work, any ideas? Also, it does have to be this way due to previous issues with i.e. 7 and 8.

HTML

<input type="checkbox" name="interest1" id="interest1" value="interested"style="display:block">
<input type="checkbox" name="interest2" id="interest2" value="interested"style="display:block">
<input type="checkbox" name="interest3" id="interest3" value="interested"style="display:block">
<p align="center">
<label for="interest_inet" id="label-interest1" onClick="func()"></label>

CSS:

label {
    border:1px solid red;
    display:inline-block;
}

#label-interest1 {
    background-image: url(images/internetbutton.gif);
    width: 152px;
    height:152px;
}

JavaScript:

<script type="text/javascript">
function func()
{
    if(document.getElementById('interest_inet').checked)
    {
        document.getElementById('label-interest1').style.backgroundImage=url(images/internetbutton.gif);
    }
    else
    {
        document.getElementById('label-interest1').style.backgroundImage=url(internetbuttonchecked.gif);
    }
}
</script>

Here is a live code example

  • 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-17T04:30:40+00:00Added an answer on June 17, 2026 at 4:30 am

    You seem to just be missing some quotes (the value of style.backgroundImage should be a string):

    function func()
    {
        var label = document.getElementById('label-interest1');
        if(document.getElementById('interest_inet').checked)
        {
            label.style.backgroundImage = 'url(images/internetbutton.gif)';
        }
        else
        {
            label.style.backgroundImage = 'url(internetbuttonchecked.gif)';
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a real world program that is similar to this one, which I'll
This problem is giving me a real headache. I have two tables in my
OK so having a real headache with this one and most of the day
I have a table that looks like this one : +------+------+------------------+ | item |
I have a input dataframe like this (the real one is very large, so
Ok, I'me getting real dumb with this one.... I have this class: Public Class
A real head-scrather this one. I have created two ApiControllers which I am using
Been having real trouble with this one and wondered if someone may have found
This one is a real head scratcher... I have a number of command links
I'm embarrassed to ask this one, it's a real newbie question but it's been

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.