Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

mbpowner

macrumors regular
Original poster
Aug 19, 2016
174
14
<!DOCTYPE html>
<html>

<head>
<title>test</title>
<script>
var table=document.getElementById("myTable");
for (var i = 0, i < table.rows.length; i++)
{
var one=(table.rows.cells[1].innerHTML);
document.write(one);
}

</script>
</head>

<body>

<table border="1" id="myTable">

<tr>
<td>a</td>
<td>b</td>
<td>c</td>
</tr>

<tr>
<td>d</td>
<td>e</td>
<td>f</td>
</tr>

<tr>
<td>g</td>
<td>h</td>
<td>i</td>
</tr>

</table>


</body>

</html>

this is just a test to see whether tables can be iterated through using this method, however no output is produced using the javascript code. can anyone suggest why? please thanks
 

960design

macrumors 68040
Apr 17, 2012
3,710
1,578
Destin, FL
can anyone suggest why? please thanks
Looks like you made a couple of mistakes:
  1. <script> in header is running before body exists... so a null return
  2. comma in for loop, instead of a semicolon
  3. missed adding the index to the row[]
Check the JSBIN ( remember to put the <script> tags right at the bottom of code, right above the closing </body> tag
https://jsbin.com/qotohofije/edit?html,js,console

PS. looks like I forgot to iterate the iterator... can you fix it?
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.