1. Home
  2. Computing & Technology
  3. JavaScript
photo of Stephen Chapman
Stephen's JavaScript Blog

By Stephen Chapman, About.com Guide to JavaScript since 2004

Display Random Image or Quote

Friday March 6, 2009
JavaScript can update your page for visitors even when you are away from your computer.

If you have a number of images, quotes, links, ads or whatever and you want to choose one of them at random to display on your page then this simple script is what you need.

Display Random Image or Quote
Comments
March 9, 2009 at 2:11 pm
(1) AD says:

What is code0, code1….?
Please explain.

Thanks

March 10, 2009 at 2:31 am
(2) Stephen says:

code0 is your first image tag or quote
code1 is your second image tag or quote
code99 is your 100th image tag or quote etc.

June 2, 2009 at 7:38 am
(3) RedFox says:

isnt that ridiculous, i mean it is ok if you have 10-15 picture, i think that would be more easy just to point to the folder with images, since i dont have all the time in the world to make thousands of ‘code_x’, and to think i have to update it every time i have to display new added pictures… its just basic of basics man!

June 2, 2009 at 3:04 pm
(4) Stephen says:

As JavaScript has no file access whatsoever that isn’t an option if you do this with JavaScript. The better way to do it is with a server side scripting language which does have such access but not everyone is using hosting with a server side language available.

Leave a Comment

Line and paragraph breaks are automatic. Some HTML allowed: <a href="" title="">, <b>, <i>, <strike>

Explore JavaScript
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. JavaScript

©2009 About.com, a part of The New York Times Company.

All rights reserved.