What I am trying to do is display an image based on button clicked. So far this is what I have. I also ran across something called. http://rvera.github.io/image-picker/
My problem is I click the first button and the first picture in the database appears but you can not get any of the other pictures to appear. I also used an ORDER BY function to test that the other photos worked and they do. So it seems stuck on the first photo in the database, or first after sorting.
<!DOCTYPE html>
<html>
<head>
<cfquery datasource="AccessTest" name="qTest">
SELECT Account, Image, Image_ID
FROM PictureDB
</cfquery>
<script src="http://code.jquery.com/jquery-2.0.3.js">
</script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("#div1").html('<img src="<cfoutput>#qTest.Image#</cfoutput>">');
});
});
</script>
</head>
<body>
<div id="div1">
<h2>
Display Image
</h2>
</div>
<cfloop query="qTest">
<button>
<cfoutput>
<tr>
<td>
#qTest.Account#
</td>
</tr>
</cfoutput>
</button>
</cfloop>
</body>
<!DOCTYPE html>
<html>
<head>
<cfquery datasource="AccessTest" name="qTest">
SELECT Account, Image, Image_ID
FROM PictureDB
</cfquery>
<script src="http://code.jquery.com/jquery-2.0.3.js">
</script>
<script>
$(document).ready(function(){
var _img = [];
<cfoutput query="qTest">
_img.push({'id': '#qTest.Image_ID#', 'src': '#qTest.Image#'});
</cfoutput>
console.log(_img);
});
$("button").on('click', function(){
var _id = $(this).data('image-id');
console.log('Image ID: ' + _id + '.');
// Find the corrosponding object in the _img array.
var result = $.grep(_img, function(e){ return e.id === _id });
// If only one is found, then reference the image src from the matching object.
if (result.length === 1) {
console.log(result[0].src);
$("#div1").html('<img src="' + result[0].src + '">');
} else {
// If none or more than one are found, show a warning.
console.warn('Could not find image ' + _id + '.');
}
});
});
</script>
</head>
<body>
<div id="div1">
<h2>
Display Image
</h2>
</div>
<cfoutput query="qTest">
<button id="account_#qTest.Image_ID#" data-image-id="#qTest.Image_ID#">
#qTest.Account#
</button>
</cfoutput>
</body>