Suppose I have the following HTML:
<div>
<input type="image" id = "mainImg> <br />
</div>
<div>
<input type="image" class = Button src = "buttonImg.jpg" onclick="showImage()">
</div>
And my JavaScript code is:
var imgArray = new Array ();
imgArray[0] = "image1.jpg"
imgArray[1] = "image2.jpg"
imgArray[2] = "image3.jpg"
imgArray[3] = "image4.jpg"
imgArray[4] = "image5.jpg"
var linkArray = new Array ();
linkArray[0] = "https://link1.com"
linkArray[1] = "https://link2.com"
linkArray[2] = "https://link3.com"
linkArray[3] = "https://link4.com"
linkArray[4] = "https://link5.com"
function diceCast(){return Math.floor(Math.random()*5);};
function showImage(){
var imgNum = diceCast();
var objImg = document.getElementById("mainImg");
objImg.src = imgArray[imgNum];
}
I would like to achieve the following:
When the user clicks on 'imgArray[0]', a new page (e.g. _blank) should load with the content from 'linkArray[0]'.
Should I assign 'imgArray[imgNum] = linkArray[linkNum]' for this to work? If so, how can I implement it?
Feel free to provide suggestions on how to make this process more streamlined and user-friendly!