Jump to content

[SOLVED] Random image onload


Mr_J

Recommended Posts

Hi all,

I have a page using some JavaScript. On-load or refresh a new image will display. This works 100% but how can I make it to display for e.g. 3 images? I have about 10 products on show or special and I want to "showcase" 3 images/products on the page.

In my <head> tag:

<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var randomTWD = 0;
var DoIt = 0;
images = new Array;
images[1] = new Image();
images[1].src = "prod/bpmonitors/bp1.PNG";
images[2] = new Image();
images[2].src = "prod/oxygen/1.PNG";
images[3] = new Image();
images[3].src = "prod/glucometers/EasyTouchGCU.PNG";
images[4] = new Image();
images[4].src = "prod/bpmonitors/bp2.PNG";
images[5] = new Image();
images[5].src = "prod/oxygen/2.PNG";
images[6] = new Image();
images[6].src = "prod/glucometers/EasyTouchGC.PNG";
function TWDpics() {
var imgnum = images.length - 1;
do {
var randnum = Math.random();
randomTWD = Math.round((imgnum - 1) * randnum) + 1;
} while (randomTWD == DoIt);
DoIt = randomTWD;
document.ImageHolder.src = images[DoIt].src;
}
// End -->
</script>

in the <body> tag:

onLoad="TWDpics();"

and where the image appear in page

<img name="ImageHolder" src="prod/img/show.jpg" width="155" height="200" border="0" alt="by SA Micro Products">

I have tried to repeat the code where the image appear but no avail...

Any help please

Thanks

 

 

Link to comment
Share on other sites

I got it right... Guess it is simple...

All I did was to duplicate the part in the head and renamed the field/image name properties. I.e.

SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var randomTWD = 0;
var DoIt = 0;
images = new Array;
images[1] = new Image();
images[1].src = "prod/bpmonitors/bp1.PNG";
images[2] = new Image();
images[2].src = "prod/oxygen/1.PNG";
images[3] = new Image();
images[3].src = "prod/glucometers/EasyTouchGCU.PNG";
images[4] = new Image();
images[4].src = "prod/bpmonitors/bp2.PNG";
images[5] = new Image();
images[5].src = "prod/oxygen/2.PNG";
images[6] = new Image();
images[6].src = "prod/glucometers/EasyTouchGC.PNG";
function TWDpics() {
var imgnum = images.length - 1;
do {
var randnum = Math.random();
randomTWD = Math.round((imgnum - 1) * randnum) + 1;
} while (randomTWD == DoIt);
DoIt = randomTWD;
document.ImageHolder.src = images[DoIt].src;
}
// End -->
</script>

added the secont part as:

<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var randompoep = 0;
var DoIt = 0;
images = new Array;
images[1] = new Image();
images[1].src = "prod/bpmonitors/bp1.PNG";
images[2] = new Image();
images[2].src = "prod/skaal/sk1.PNG";
images[3] = new Image();
images[3].src = "prod/glucometers/EasyTouchG.PNG";
images[4] = new Image();
images[4].src = "prod/bpmonitors/bp2.PNG";
images[5] = new Image();
images[5].src = "prod/oxygen/2.PNG";
images[6] = new Image();
images[6].src = "prod/glucometers/EasyTouchGC.PNG";
function poeppics() {
var imgnum = images.length - 1;
do {
var randnum = Math.random();
randompoep = Math.round((imgnum - 1) * randnum) + 1;
} while (randompoep == DoIt);
DoIt = randompoep;
document.ImageHolder1.src = images[DoIt].src;
}
// End -->
</script><SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var randompoep = 0;
var DoIt = 0;
images = new Array;
images[1] = new Image();
images[1].src = "prod/bpmonitors/bp1.PNG";
images[2] = new Image();
images[2].src = "prod/skaal/sk1.PNG";
images[3] = new Image();
images[3].src = "prod/glucometers/EasyTouchG.PNG";
images[4] = new Image();
images[4].src = "prod/bpmonitors/bp2.PNG";
images[5] = new Image();
images[5].src = "prod/oxygen/2.PNG";
images[6] = new Image();
images[6].src = "prod/glucometers/EasyTouchGC.PNG";
function poeppics() {
var imgnum = images.length - 1;
do {
var randnum = Math.random();
randompoep = Math.round((imgnum - 1) * randnum) + 1;
} while (randompoep == DoIt);
DoIt = randompoep;
document.ImageHolder1.src = images[DoIt].src;
}
// End -->
</script>

The only values I changed was: randomTWD to randompoep in the second script code...

Hope it can help someone in the future

Jaco

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.