I have created javascript to get random images and display them to div elements on the html page.
I have the code working so far as generating random images ok.
the problem.....
i have 5 div elements....sometimes the same images is showing 2 or more times on different div areas and i want each one of the 5 div areas to display different images from the array.
You aren't checking the numbers you generate are unique, consequently the same images can be appear. Rather than generating 5 numbers, why don't you randomise the array of images and then just output the first 5 elements?
instead of writing random images to my div tags only once it writes EVERY single image in the array and populates my div areas with not just one image but all of them in the array and covers the whole page lol.
i will keep searching but if anyone else has any suggestions i am all ears.
i think am looking for a conditional statement that says image placeholder 1 should differ from image place holder 2 and so on and so forth...
I guess you've changed your script to what onion2k suggested, and that it has resulted in the new problem. In that case, post your new code.
EDIT:
It would seriously be alot neater if you followed what onion2k suggested. Just put all the images into an array, randomize it, and output the first 5.
jayshields wrote:I guess you've changed your script to what onion2k suggested, and that it has resulted in the new problem. In that case, post your new code.
EDIT:
It would seriously be alot neater if you followed what onion2k suggested. Just put all the images into an array, randomize it, and output the first 5.
Thank you for your comments.
But, as per my previous post, the problem is now sorted and working perfectly.