View Single Post
Old 03-03-2012, 04:48 PM   PM User | #3
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,105
Thanks: 197
Thanked 2,421 Times in 2,399 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Try this:-

Code:
<html>
<head>
</head>
<body onload = "listem()">

<script type = "text/javascript">

function listem(){
var myArray = new Array();  // text of the links
myArray[0] = "Bob's Website";
myArray[1] = "Jim's Website";
myArray[2] = "Jill's Website";
myArray[3] = "Google";

var links = new Array();
links[0] = "http://www.bobswebsite.com";  // corresponding urls
links[1] = "http://www.jimswebsite.com";
links[2] = "http://www.bobswebsite.com";
links[3] = "http://www.google.com";

for (var i=0; i <myArray.length; i++) {
document.write(myArray[i].link(links[i]));
document.write("<br>")
}

}
</script>

</body>
</html>
You should be aware that document.write() statements must (as here) be run before the page finishes loading. Any document.write() statement that runs after the page finishes loading will create a new page and overwrite all of the content of the current page (including the Javascript which called it). So document.write() is at best really only useful to write the original content of your page. It cannot be used to update the content of your page after that page has loaded.

"I know that you believe that you understand what you think I said, but, I am not sure you realise that what you heard is not what I meant". (Robert
McCloskey)
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.

Last edited by Philip M; 03-03-2012 at 04:54 PM..
Philip M is offline   Reply With Quote