Jump to content

Display Array


locbtran

Recommended Posts

I would like to display the elements in my array but it is NOT working. Here's my code:

<HTML><HEAD><TITLE>Test Input</TITLE><script type="text/javascript">function addtext() {   var openURL=new Array("http://google.com","http://yahoo.com","http://www.msn.com","http://www.bing.com");   document.writeln('<table>');   for (i=0;i<=openURL.length-1;i++){      document.writeln('<tr><td>openURL[i]</td></tr>');   }   document.writeln('</table>');}</script></HEAD><body onload="addtext()"></BODY></HTML>

Here's the ouput:

openURL[i] openURL[i] openURL[i] openURL[i]

It should display:

http://google.comhttp://yahoo.comhttp://msn.comhttp://bing.com

Any comments or suggestions are greatly apprecitated.thanks

Link to comment
Share on other sites

  • 2 weeks later...
document.writeln('<tr><td>openURL[i]</td></tr>');

should be

document.writeln('<tr><td>'+openURL[i]+'</td></tr>');

otherwise the openURL will be treated like a part of the string as opposed to a JavaScript object.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...