Jump to content

Change image when selected


dc_jt

Recommended Posts

Hi Im having a problem with the following:

 

I have four images, a red image, vanilla, chocolate and caramel.

 

These are in a form and upto two need to be selected, no more!

 

I have created four hidden checkboxes to act for each colour and now need to somehow say if the red checkbox is checked then show a certain image else show a different image.

 

How do I do this? Here is an example so far of the red button:

 

function checkColour(myColour) {
    	
        if (document.getElementById(myColour).checked == false){
        document.getElementById(myColour).checked=true;
        } else {
        document.getElementById(myColour).checked=false;
        }
    }

<li><a onclick="javascript:checkColour('red');"><img src="../assets/images/shop/flavour-red-off.gif" alt="red" width="30" height="30" border="0" /></a>Red</li>

<div style="display:none">
<input name="red" type="checkbox" id="red">red
</div>

 

As you can see at the moment the checkColour function checks the hidden checkbox, however I now need to change the flavour-red-off.gif image to flavour-red-on.gif if its checked.

 

Hope someone can help

 

THanks

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.