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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change Images on Page

Status
Not open for further replies.

WalksWithSky

Instructor
Dec 11, 2002
49
CA
Hello:

Just wondering if anyone knows how to change images on the page when the page is loaded. I've seen this on a lot of sites, and someone told me it's done with Javascript. Most notably, is the perfect example of what I'm looking to do -- change the colour schemes of the image on my page. Anyone have any thoughts, or am I in the wrong place?

Walks With Sky
 
Easiest way is to load the images into an array and select one randomly...

<script>
imgArr = new Array(&quot;img0.jpg&quot;,&quot;img1.jpg&quot;,&quot;img2.jpg&quot;,&quot;img3.jpg&quot;,&quot;img4.jpg&quot;)

function showPic(){
picNum = Math.floor(Math.random() * (imgArr.length))
if (picNum == imgArr.length){
picNum --
}
document.mainPic.src = imgArr[picNum]
}

</script>

<body onLoad=&quot;showPic()&quot;>
<img src=&quot;starwarsPic.jpg&quot; name=&quot;mainPic&quot;>


The Star Wars page is more elegant, but the theory is the same... Get the Best Answers! faq333-2924
Is this an asp FAQ? faq333-3048
Tek-Tips Best Practices: FAQ183-3179
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top