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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:46:21+00:00 2026-05-28T02:46:21+00:00

usual but I need to have different custom radio button images per button. So

  • 0

usual but I need to have different custom radio button images per button.

So Radio1 would have different images to Radio2.

Trying it out on the code below but it won’t work so I must be doing something wrong?

Here’s the code:

<label for="radio1">
    <img src="radio1_unchecked.png" style="vertical-align:middle" />
    <input name="radiogroup" type="radio" id="radio1" style="display:none;">
</label>

<label for="radio2">
    <img src="radio2_unchecked.png" style="vertical-align:middle" />
    <input name="radiogroup" type="radio" id="radio2" style="display:none;">
</label>

<script>
 $(document).ready(function(){

var radio1checkedImage = "radio1_checked.png",
    radio1uncheckedImage = "radio1_unchecked.png",
    radio2checkedImage = "radio2_checked.png",
    radio2uncheckedImage = "radio2_unchecked.png";

   $('img').attr("src", radio1uncheckedImage);

$('#radio1, #radio2').change(function() {
  var r;

  r = $("#radio1");
  r.prev().attr("src", r[0].checked ? radio1checkedImage : radio1uncheckedImage);

  r = $("#radio2");
  r.prev().attr("src", r[0].checked ? radio2checkedImage : radio2uncheckedImage);

});


});

</script> 

Update: Here is the same code as above but without the multiple images.
As you can see it works. Can’t the code be modified to have multiple images per radio?

  • 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-05-28T02:46:22+00:00Added an answer on May 28, 2026 at 2:46 am

    In addition my other answer, which uses CSS, let me offer an alternative solution.

    Firstly; you want to keep track of which image goes with which radio button. Why not use an object literal?

    var checkedImages = {
        'radio1': "radio1_checked.png",
        'radio2': "radio2_checked.png"
    };
    var uncheckedImage = "unchecked.png";
    

    This way you can easily refer to the different URL’s like, e.g.: checkedImages['radio2'].

    The change event handler would look very similar. The only difference is what you do with the checkedLabels and the uncheckedLabels:

    var radios = $('input:radio');
    
    radios.change(function() {
        var checkedLabels = radios.filter(':checked').parent();
        var uncheckedLabels = radios.filter(':not(:checked)').parent();
    
        uncheckedLabels.children('img').attr('src', uncheckedImage);
    
        checkedLabels.each(function() {
            var image = $(this).children('img');
            var name = $(this).attr('for');
    
            if (checkedImages[name] !== undefined) {
                // We have checked image for this radio button, so set it:
                image.attr('src', checkedImages[name]);
            } else {
                // We don't have checked image for this radio button.
                image.attr('src', uncheckedImage);
            }
        });
    });
    

    The main differences:

    • We use children() to find the images.
    • We use each() to add more complicated logic for each of the unchecked label.
    • We check the selected <label>s for attribute (using .attr('for')) to find out which image we should apply.

    In this example only the checked state has different images for the different radio’s. If you need different unchecked images as well, you can easily apply the same principle.

    Live example: http://jsbin.com/acalir/edit#javascript,html,live

    P.S. don’t forget to set the src to the unchecked images (in HTML), or do the following (in JS):

    $('input:radio').change();
    

    This fires the change event programmatically, which will cause the unchecked images to be applied.

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

Sidebar

Related Questions

I am trying to make a query as usual but this time I need
I have the following code and it's working (as usual) in everything but IE.
this is really stupid, but I been trying dozens of different things and I
We have the usual web.xml for our web application which includes some jsp and
We have a Seam 2 based web application with the usual user login and
I have a long list of links that I spit out using the below
I made textbox, but it needs to send data to other application, which have
So I am really stumped because I have basic ideas but I am looking
I have 2 arrays of 16 elements (chars) that I need to compare and
I'm currently developing an iPad application that integrates MapKit. But I have a small

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.