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
https://forums.phpfreaks.com/topic/91846-change-image-when-selected/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.