0

I have been researching ways to submit a form with the images selected by users. I will give the users a set of Images , they can choose multiple.

Method 1 If image is selected, add input via onclick() with the selected Value. [Possible?]

Method 2 For each Img , load hidden input , let users delete that they don't want. [Weird]

Any advice / example i can look at?

TransformBinary
  • 268
  • 3
  • 17

2 Answers2

1

I would use invisible checkboxes with the img tag inside the label for it. That way, a click on the image should in theory trigger the checkbox.

kinghfb
  • 1,011
  • 5
  • 14
1

Add an extra class with the img tag's class attribute. What you can do is create a click function for those images and their ID's via JQuery. Let's make an img tag and see how it can work

In JQuery, do the following

var imgIDs = "";
$('.multImg').click(function(){
    imgIDs += $(this).attr('id')+",";
});

You'd most probably want to keep the record of the images user has clicked on and send it to the server. But before you do, do not forget to remove the trailing ",". You can achieve that by

imgIDs = imgIDs.substring(0, imgIDs.length - 1);

On server end, you can simple use explode and have all the IDs in an array. Those are the IDs of the images user has selected. You can do whatever you want with the array now.

Basit
  • 1,830
  • 2
  • 31
  • 50
  • What about, Unclick? :x – TransformBinary Dec 06 '13 at 14:29
  • Simply get the ID of the image the user's selected again and remove that from the string. Here's how you can do that http://stackoverflow.com/questions/12582164/how-to-remove-a-substring-between-two-specific-characters – Basit Dec 09 '13 at 05:09