Retrieve user's image selection from website

- 1 answer

Ad

I am trying to make a website where the user needs to pick one image from a selection presented on the site. When the user selects a picture, i.e. clicks on it, I somehow need to retrieve the name/ID of the selected photo, and have this available on the server.

This is because I must run a bash script on my server, with the selected image ID as input.

What is the simplest way this can be achieved?

Ad

Answer

Ad

Here's how to find the id of the element you clicked ...

$(document).ready(function() {
  $(".some-image").click(function(event) {
    // do something with the  image id below
    console.log(event.target.id);
  });
});

Copied almost entirely from this stack-overflow question/answer here

Ad
source: stackoverflow.com
Ad