"Global_Killa" wrote
Quote:
I'm new to java script, and really don't know anything about it. I'm
looking to have a random link shown on my site. I want the link to be
chosen
from a list of about 10 links.
How would I go about this? I found this piece of code, but this only
allows
two links. Does anyone know how to expand on this to add 10 or more?
snip |
There are many ways to do this. Close to your original code, but allowing
for an arbitrary number of links, is this:
thelinks=['www.yahoo.com/','www.google.com/','www.c.com/','www.d.com/'];
thetexts=['Yahoo','Google','c','d'];
a=Math.floor(thelinks.length*Math.random());
document.write('<a href="http://'+thelinks[a]+'">'+thetexts[a]+'</a>');
It should be mostly self-explanatory, if it isn't, let us know.
HTH
Ivo