Jump to content

Two Random Site Generators On One Page?


pmhabo
 Share

Recommended Posts

I have a random site generator on my website, but the questions is how do I get 2 different ones to work with two different lists?Here is the code I'm using for the first:<script type="text/javascript" language="javascript">//replace href with site urls, linktext with displayed text/flyover title - all in quotesvar sitepicks = new Array({href: "http://www.random.com" , linktext: "sitename"} ,{href: "http://www.random.com" , linktext: "sitename"} //no trailing comma!!!);</script><!-- embed this where you want the links to appear --><script type="text/javascript" language="javascript">var site, rnd, HTML = "", numOfSites = 5; //adjustwhile (numOfSites--) {rnd = Math.floor(Math.random() * sitepicks.length);site = sitepicks[rnd];HTML += '<a class="randlinks" href="' + site.href + '" title="' + site.linktext;HTML += '">' + site.linktext + '</a><br>';sitepicks.splice(rnd,1);}document.write(HTML);</script>How do I change it for the second so it doesn't mess with the first?

Link to comment
Share on other sites

How do I change it for the second so it doesn't mess with the first?
Like Synook said, you need another array. In order not to break anything, make sure your array and the code after uses different names from the first set. You have this part where you define the array:
var sitepicks = new Array({href: "http://www.random.com" , linktext: "sitename"} ,{href: "http://www.random.com" , linktext: "sitename"} //no trailing comma!!!);

The array is called sitepicks. You need to copy everything you have and change the name, use something other than sitepicks for the second array. In the code that follows, change sitepicks wherever you see it to whatever you called the second array.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...