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

document.writeln('<tr><td>openURL</td></tr>');Should be: document.writeln('<tr><td>'+openURL+'</td></tr>');Looks like you forgot to use JavaScript's concatenation operator ( + ), when combining strings with variables etc.

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

document.writeln('<tr><td>openURL</td></tr>');Should be: document.writeln('<tr><td>'+openURL+'</td></tr>');Looks like you forgot to use JavaScript's concatenation operator ( + ), when combining strings with variables etc.
How would I put my array into the window.open() function
document.writeln('<tr><td> <a href = "" onclick="window.open(\'http://google.com\'); return false;">'+openURL[i]+'</td></tr></a>');

So instead of window.open(\'http://google.com\');I tried window.open(\'+openURL+\'); but it does NOT work

Link to comment
Share on other sites

How would I put my array into the window.open() function
document.writeln('<tr><td> <a href = "" onclick="window.open(\'http://google.com\'); return false;">'+openURL[i]+'</td></tr></a>');

So instead of window.open(\'http://google.com\');I tried window.open(\'+openURL+\'); but it does NOT work

You forgot to close/reopen the string. Ie,document.writeln('<tr><td> <a href = "" onclick="window.open(\''+openURL+'\'); return false;">'+openURL+'</td></tr></a>');
Link to comment
Share on other sites

Archived

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

×
×
  • Create New...