Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap

BBS: Re: load random image w/ matching link - September 09, 1998 at 21:11:36

You are here: irt.org | BBS | Re: load random image w/ matching link [This BBS is closed]

Posted by Rafael Coletti on September 09, 1998 at 21:11:36:

In Reply to: load random image w/ matching link posted by Ryan on September 09, 1998 at 20:35:52:

: Hi, I had a quick question concerning a script for banners and links. I host six different Safe-Audit banners. These banner are pulled from my server, not Safe-Audit's. Of these six banners, I would like a random one to load with each page. Along with each banner, the matching link must load. Below is the code for each of the six banners. Could someone write a quick script that would accomplish what I'm attempting?

Hi Ryan, let's get that problem fixed, I'm not going through the whole coding, but I'll try to put as much details as I find necessary. First you'll need to make a function that chooses 1 of 6 numbers randomly... I'll use my function depending on the time your visitors access your page, there're many other possibilities, but this one is the easiest.

This function will get the time then the seconds of the time and reduce them to 6 numbers.

var now=new Date (), number = now.getSeconds ()%6;

Next you'll do a serie of ifs to test the numbers coming from the previous function.

if (number == 0) {document.write ('<A HREF="..."><IMG SRC="...">');}
if (number == 1) {document.write ('<A HREF="..."><IMG SRC="...">');}
if (number == 2) {document.write ('<A HREF="..."><IMG SRC="...">');}
if (number == 3) {document.write ('<A HREF="..."><IMG SRC="...">');}
if (number == 4) {document.write ('<A HREF="..."><IMG SRC="...">');}
if (number == 5) {document.write ('<A HREF="..."><IMG SRC="...">');}

Remember - for the random function I'm using in this example the first number that comes out is 0 and the last one is 5 to a total of 6 numbers that are choosen more or less randomly. If you want a more robust radom function go to the articles page, there's is a nice one there.

I hope you got the idea, if not I'll enter in more details


You are here: irt.org | BBS | Re: load random image w/ matching link [This BBS is closed]

©2018 Martin Webb