pmhabo Posted October 15, 2009 Share Posted October 15, 2009 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 More sharing options...
Synook Posted October 15, 2009 Share Posted October 15, 2009 Create a second array. Link to comment Share on other sites More sharing options...
justsomeguy Posted October 15, 2009 Share Posted October 15, 2009 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 More sharing options...
pmhabo Posted October 15, 2009 Author Share Posted October 15, 2009 thats what i already tried. it isn't working Link to comment Share on other sites More sharing options...
pmhabo Posted October 15, 2009 Author Share Posted October 15, 2009 do i have to change all the variables in the second part or something too? Link to comment Share on other sites More sharing options...
justsomeguy Posted October 15, 2009 Share Posted October 15, 2009 You only need to change the name of the array everywhere it's used. If it's not working, show your code. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.