So I have a Javascript function. It is passed a folder name, say “A”.
This folder contains 5 images which will be picked randomly.
It works well on the page load, as 1 random image appears. But I want it so that
when the image is clicked, it is randomized again with an image from the same folder. I tried to go about this with the onmousedown, but it returns a broken image link to
file:///C:/Users/StackOverflow/Documents/Website/[object%20HTMLDivElement]/2.jpg
<script type="text/javascript">
// <![CDATA[
function showImage(folder){
var randomNumber=Math.floor(Math.random()*5);
document.write('<img src="'+folder+'/'+randomNumber+'.jpg" onmousedown="showImage('+folder+')">');
}
//]]>
</script>
I don’t think you really want to be calling
document.write()every time the image is clicked. Perhaps you would have more success with a setup like: