I have made a function that generates a random link and some text. I haven't put it on my site yet(so the links and text aren't what they're going to be), but I've already encountered a problem. I can't use document.write to display it in the body section of the document. Right now it's in the function and that causes it to rewrite all the contents of the webpage. Here is the code: function num_random() { var num= Math.floor(Math.random()*5); return num; } function randomlinks() { var quoteNumber=num_random(); var quote=new Array(5) quote[0]="static text <a href='http://www.google.com/'>link text1</a> static text <a href='http://www.google.com/'>link text2</a>"; quote[1]="static text <a href='http://www.newgrounds.com/'>link text3</a> static text <a href='http://www.newgrounds.com/'>link text4</a>"; quote[2]="static text <a href='http://www.webdeveloper.com/'>link text5</a> static text <a href='http://www.webdeveloper.com/'>link text6</a>"; quote[3]="static text <a href='http://www.weebls-stuff.com/'>link text7</a> static text <a href='http://www.weebls-stuff.com/'>link text8</a>"; quote[4]="static text <a href='http://www.amazon.com/'>link text9</a> static text <a href='http://www.amazon.com/'>link text10</a>"; var outputText=quote[quoteNumber] document.write(outputText); } The document.write statement works right now, erasing everything else. I would like to move it to <body>. I dunno why this doesn't work, it just stays blank.
For the benefit of those who may be looking for the same answer, could you please post the solution you came up with?
Somebody proposed a simpler script and it worked. I still don't know why Here it is: links=Array() links[0]="text1 <a href='test.html'>Link 1</a> text <a href='test.html'>Link 2</a> text <a href='test.html'>Link 3</a>" links[1]="text1 <a href='test.html'>Link 4</a> text <a href='test.html'>Link 5</a> text <a href='test.html'>Link 6</a>" links[2]="text <a href='test.html'>Link 7</a> text <a href='test.html'>Link 8</a> text <a href='test.html'>Link 9</a>" links[3]="text <a href='test.html'>Link 10</a> text <a href='test.html'>Link 11</a> text <a href='test.html'>Link 12</a>" links[4]="text <a href='test.html'>Link 13</a> text <a href='test.html'>Link 14</a> text <a href='test.html'>Link 15</a>" function rand() { return Math.round(Math.random()*(links.length-1)) } document.write(links[rand()])