Ehsan Qureshi Ehsan Qureshi - 6 months ago 11
HTML Question

Random Image with Random Links

<html>
<body>
<script>

var images_src = ["PrizeImage-1","PrizeImage-2","PrizeImage-3",];
var links = ["Participate1","Participate2","Participate3","Participate4",];

</script>
<a href="random_link" ><img src='random_img' alt='image'></a>
</body>
</html>


how can I call random links with random image in a single HTML page

Answer

If you want to set the image and link with random values you can do it like this:

HTML

<a href="random_link" id="linkEl"><img id='imgEl' src='random_img' alt='image'></a>

JAVASCRIPT

var Links = ["Link1" , "Link2" , "Link3" , "Link4"];
var images_src = ["Image1" , "Image3" , "Image3" , "Image4"];

var randomLink = Links[parseInt(Math.random()*Links.length)]; //Get random link (with random number from 0 to the link array's length
var randomImage= images_src[parseInt(Math.random()*images_src.length)];//Get random image
var linkEl = document.getElementById('linkEl'); //Get link element
var imgEl = document.getElementById('imgEl'); //Get image eement

linkEl.href = randomLink; //Set the link
imgEl.src = randomImage; //Set the image

For more funcionality, you should provide more detail, but this might get you going hopefully.