Jump to content


Multiple JS Random Image Scripts?


  • You cannot reply to this topic
No replies to this topic

#1 SimplicityDesigns

    BaseballHeadDan

  • Members
  • Pip
  • 136 posts
  • Interests:Web/graphics design

Posted 25 September 2006 - 05:05 PM

I'm trying to do two random image scripts on one page. I put each of the JS scripts in separate external files and linked to them. Here are my two scripts:
var theImages = new Array()
theImages[0] = 'images/testimonials/1.gif'
theImages[1] = 'images/testimonials/2.gif'
theImages[2] = 'images/testimonials/3.gif'
theImages[3] = 'images/testimonials/4.gif'
theImages[4] = 'images/testimonials/5.gif'
theImages[5] = 'images/testimonials/6.gif'
theImages[6] = 'images/testimonials/7.gif'
theImages[7] = 'images/testimonials/8.gif'
theImages[8] = 'images/testimonials/9.gif'

var j = 0
var p = theImages.length;
var preBuffer = new Array()
for (i = 0; i < p; i++){
   preBuffer[i] = new Image()
   preBuffer[i].src = theImages[i]
}
var whichImage = Math.round(Math.random()*(p-1));
function showImage(){
document.write('<img src="'+theImages[whichImage]+'" border="0px">');
}

_________________________

var homeImages = new Array()
theImages[0] = 'images/headimage_home_a.jpg'
theImages[1] = 'images/headimage_home_b.jpg'
theImages[2] = 'images/headimage_home_c.jpg'
theImages[3] = 'images/headimage_home_d.jpg'

var j = 0
var p = homeImages.length;
var preBuffer = new Array()
for (i = 0; i < p; i++){
   preBuffer[i] = new Image()
   preBuffer[i].src = homeImages[i]
}
var whichImage = Math.round(Math.random()*(p-1));
function topImage(){
document.write('<img src="'+homeImages[whichImage]+'">');
}

As you can see, I tried giving both scripts a different function and variable. What I get when I test the page is the first image from the second script appearing where the other image(s) should.

Help is appreciated.

-dan





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users