PDA

View Full Version : Image to Checkbox



boogily
Jul 19th, 2009, 08:43 PM
It may sound simple, but so far it isn't. I'm helping out with a website with a page that is coded in php. In the file, there are tables set up. One has 6 checkboxes in a row.

The next are six pictures.

How do I make it so when you click on the pictures, the appropriate checkboxes will be checked?

brandon1
Jul 19th, 2009, 11:55 PM
heres a quick example of how that works
http://www.blendedcodes.com/RZN1OgZT

its faster to learn this type of thing by example, the link contains a live test environment with my code in it for ya.

hope this was helpful!

MattF
Jul 19th, 2009, 11:56 PM
Use labels tags. You can do it in a couple of slightly different ways.



<label><img src="[path to image]"/>
<input type="checkbox" name="checkbox1" value="[value]"/>
</label>


or:



<label for="checkbox1"><img src="[path to image]"/></label>
<input type="checkbox" id="checkbox1" name="checkbox1" value="[value]"/>


The second method is preferable, in my opinion. The 'for=' has to match the checkbox id to tie the label to the input.