locbtran Posted August 25, 2011 Share Posted August 25, 2011 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 More sharing options...
Don E Posted August 25, 2011 Share Posted August 25, 2011 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 More sharing options...
locbtran Posted August 25, 2011 Author Share Posted August 25, 2011 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() functiondocument.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 More sharing options...
Drycodez Posted August 25, 2011 Share Posted August 25, 2011 window.open(openURL) Link to comment Share on other sites More sharing options...
ShadowMage Posted August 25, 2011 Share Posted August 25, 2011 How would I put my array into the window.open() functiondocument.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 More sharing options...
Don E Posted August 25, 2011 Share Posted August 25, 2011 Just for reference, the closing 'a' tag should come before the closing td and tr tags, if you're following xhtml. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.