UPDATE: see bryanbraun answer . Its much better.
In HTML, <input type="image"> is just a submit button with an image as a face. I do not think you want. You probably need a list of actual images that, when clicked, sets the value of the hidden shape according to the value-value attribute. So your HTML should look something like this:
<form id="select-form"> <img src="image.jpg" data-value="image_value"> <img src="image2.jpg" data-value="image_value2"> <input type="hidden" id="image-value" name="selected_image" value=""> </form>
Then in your javascript you want to both select the image and set a hidden value, for example:
$('#select-form img').click(function() { // Set the form value $('#image-value').val($(this).attr('data-value')); // Unhighlight all the images $('#select-form img').removeClass('highlighted'); // Highlight the newly selected image $(this).addClass('highlighted'); });
Finally, set some styles for the highlight class in your CSS file:
img.highlighted { border: 2px solid blue; }
Ben lee
source share