Random Image Selection using JavaScript

This little example uses JavaScript to generate a random number and then select an image to display in the slot to the right. This could be used on ahome page to create an image that changes (randomly) each time the user comes to the page.

A couple of note:

  • This example uses 5 images, but you could have as many as you want in the selection set. The more images, the less likely the user will see the same image upon returning to the site.
  • Each image must be sized to the same size.
  • Use view source to see the JavaScript code. There are multiple ways to do this type of thing...this is just one solution.