Display images instead of radio buttons without using JQuery [duplicate]
I would like to display a set of images and invoke some action based on user selection using JavaScript. The image list is populated dynamically. So I am using radio buttons in order to get the image name which the user has selected. But I dont w开发者_如何学Goant the radio buttons to appear on the page. Is it possible to retrieve the value of the image selected by the user?
NOTE: The image list is populated dynamically in a loop.
Other JavaScript outside of jQuery can do this but I'm assuming that you aren't going to want to use this either as jQuery is really only a JavaScript library and you haven't specified a programming language to do this with.
Without knowing the rest of the code, what the form is doing or programming language you're using, I would suggest creating a hidden field and a single submit button per image. You may even be able to display the image as a background to the button.
The basic code for this may look something like:
<form id="image_select_1" method="post" action="processor.php">
<img src="path/to/img.png" />
<input type="hidden" id="img_1" value="image_id" />
<input type="button" value="Chose Image 1" />
</form>
You would need to do this for each image you want to use. I use a similar method for an object oriented application I have.
There are various techniques for doing this and it is just a start for you, where you take it or even if it is viable for you will depend greatly on the information you have not provided including the programming language, the rest of your code and what the purpose of the function is.
I hope this helps to get you on the right path but the more information you provide the better.
精彩评论