Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Onload Random Images in a web page

Status
Not open for further replies.
Sep 29, 2002
524
US

I am trying to use the following code in order to generate a random image. However, it gives me errors when I try to load the page using <body onload="newImage()"> and if I use <body background=onload="newImage()"> no errors show up but the images doesn't either. Can anyone advise me what am I doing wrong?

Code:
// Returns a Random Image

n = 0;

MyImages = new Array();
MyImages[0] = '/images/bg.jpg';
MyImages[1] = '/images/bg1.jpg';
MyImages[2] = '/images/bg2.jpg';

function newImage() {

currentIndx = Math.round(Math.random() * 3)
document.theImage.src = MyImages[n]
}


Gladys Rodriguez
GlobalStrata Solutions
Computer Repair, Website Design and Computer Consultant
Small Business Resources
 
Apart from the fact that your script should always load the first image, because you're always sending the value 'm' there, this question is more suited for the Javascript forum (forum216). Make sure you tell them what 'theImage' actually is in your html.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top