Display Random Image or Quote
Join the Discussion
Related Pages
Do you have a number of ads that you use on your site and you want to randomly select which one displays when someone sees the page? Do you want to choose one of a selection of quotes or images to display on your page? This simple Javascript sets up an array of all of your possible entries and then randomly chooses the one that will actually be included in the page.
The first step in using this script is to select the code from the text box below (there is a highlight all button beneath it to make this easier) and copy it into a file called rand.js.
You now need to update this code to specify the images or quotes that you want to use. First you need to repeat the code0 line as many times as necessary until the array contains as many entries as you wish to include in the random selection (it has three to start with so if you want 10 choices repeat the line an additional seven times).
If you are using quotes you then simply replace the code0, code1, and code2 references with the text for your quotes. If you want to use this code to display a random image then you need to place all of the HTML code for each of your images into the entries instead. You can make just about any type of code for your page into a random selection by placing the appropriate HTML and text into the entries.
Finally, you attach the script into your web page in the body section of your page where you want the link or message to appear using the following code:
</script>

