I am using the following script to create an image gallery, people click the checkbox under the images they want and then submit them to me. This works fine, but I have now added Jquery Fancybox which opens the larger version of the image into a lightbox. The script then creates a link under the lightbox image "Select This Image". What I am trying to do is when the user clicks on that link it then checks / unchecks (if the user presses the link again) the select box under the image on the main page. I cant seem to get it to work though, this is what I have :
This is the Jquery :
<script>
$(document).ready(function() {
$(".fancybox-thumb").fancybox({
afterLoad: function() {
this.title = '<a class="selectlink" href="#" id="' + this.title + '">Select This Image</a> ';
},
prevEffect : 'none',
nextEffect : 'none',
helpers : {
title : {
type: 'outside'
},
thumbs : {
width : 50,
height : 50
}
}
});
});
$(function () {
$('#selectlink').click(function () {
$('.imagewrapper').find(this.id).attr('checked', this.checked);
});
});
</script>
This is the html / php part :
$sql2 = <<<SQL
SELECT *
FROM `albums`
WHERE albumid = '$albumid' AND isalbum = ''
SQL;
if(!$result2 = $db->query($sql2)){
die('There was an error running the query [' . $db->error . ']');
}
while($row2 = $result2->fetch_assoc()){
echo '<div class="imagewrapper">';
echo '<a title="'.$row2['image'].'" class="fancybox-thumb" rel="fancybox-thumb" href="albums/'.$albumid.'/800x600/'.$row2['image'].'"><img style="border-radius:5px;" src="albums/'.$albumid.'/thumbnails/'.$row2['image'].'" /></a>';
echo '<div style="text-align:center;">';
echo '<strong>Select : </strong><input type="checkbox" name="'.$row2['image'].'" id="'.$row2['image'].'" />';
echo '</div>';
echo '</div>';
}
What is happening is the link is being created in the lightbox popup just fine and the title of the link is the file name e.g 123456.jpg , but when I click the link, the checkbox with the id of 123456.jpg doesnt get ticked ?.