I've searched the web and all through old Stack Overflow posts. I've been trying a method suggested where you use the html tag with an empty src="" address:
<img id = "imageid" src="">
and then the corresponding Javascript code:
function randomImg(){
var randomNumber = Math.floor(Math.random() * 12) + 1;
var imgName = "img_" + randomNumber + ".jpg";
document.getElementById("imageid").src= YOUR_IMG_PATH + "/" + imgName ;
}
Thus, I have 12 images, all named img_1.jpg through img_12.jpg, and yes, I have checked their director and got them to load via this function on my website, oddly enough, only through using this code for a button. I have not been successful simply getting the image to load via the standard html img tag:
<button type="button" onclick="randomImg()">Try it</button>
I've seen other old posts that recommend using document.onload = function() but that did not work for me (I also found a post where a Stack Overflow user stated document.onload will NOT generate a img src address for empty src=""
tag). I've always tried formatting things differently, i.e. using '' instead of "" for certain parts of the code.
My last effort will be to use an array, but I wanted to see if I could possible solve this the way I'm doing it now because I feel I am missing something completely basic and obvious.
The website is http://aemaeth0.github.io