I have two tasks i wish to accomplish.
- Store id of an image when it is clicked... so say image with an id of 3 is clicked this i wish saved to a variable for use later
2.Next i wish to then take this variable to another function and use within an if conditional
The issue here is i havent an idea as to how to do this... i get the id through a for loop and these ids are random so it needs to be when the image is clicked the id from the image is displayed and then placed into the variable. The next part is a simple search mechanism using the id so that it displays only one result depending on which image is chosen
so img is clicked - id is saved in var - var is passed to function
Here is the code
This is the function which creates the images from the json data
function getExhibitions()
{
$('#searchcontent').hide();
$('#searchby').hide();
$('#detailscontent').hide();
$('#exhibitioncontent').show();
$('#exhibitioncontent').empty();
myExhibitionsView = document.getElementById('exhibitioncontent');
images = document.createElement('ul');
for (var i = 0; i < json.length; i++) {
for (var j = 0; j < json[i].exhibits.length; j++) {
listCheck = document.createElement('div');
listCheck.id = "image";
listCheck.innerHTML = "<a href= '#imagechoice'>" + "<img id=" + json[i].exhibits[j].exhibit_id + " " + "onclick='getImagesDetails();' src = " + "./images/" + json[i].exhibits[j].exhibit_image + " height='200' width='200'" + ">";
myExhibitionsView.appendChild(images);
images.appendChild(listCheck);
}
}
}
now is the function i wish the image id passed to
function getImagesDetails(){
$('#exhibitioncontent').hide();
$('#searchby').hide();
$('#searchcontent').hide();
$('#detailscontent').show();
details = document.createElement('ul');
var exhibit_id;
json.forEach(function (element) {
for (var j = 0; j < element.exhibits.length; j++) {
if (element.exhibits[j]['exhibit_id'] === exhibit_id) {
var listDetails;
listDetails = document.createElement('p');
listDetails.id = 'image' + j;
listDetails.innerHTML = "<img src = " + "./images/" + element.exhibits[j].exhibit_image + " height='400' width='400'>" + " " + "Title = " + element.exhibits[j].exhibit_title + '</br>'
+ "Description = " + element.exhibits[j].exhibit_description + '</br>'
+ "Photography By = " + element.exhibits[j].photographer ;
console.log(listDetails);
$("#detailscontent").empty().append(details);
details.appendChild(listDetails);
}
}
});
}
the exhibit_id is where i want to store the uniquely generated id. Thanks i appreciate any assistance in this problem