Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q1601 Is there any way to retreive the text from a table cell based on its position in a table (e.g. cell 5,3)?

You are here: irt.org | FAQ | JavaScript | Table | Q1601 [ previous next ]

Use the id attribute to fake it:

<table>
<tr>
   <td id="r1c1">row 1 cell 1</td>
   <td id="r1c2">row 1 cell 2</td>
</tr>
<tr>
   <td id="r2c1">row 2 cell 1</td>
   <td id="r2c2">row 2 cell 2</td>
</tr>
</table>

<script language="JavaScript"><!--
if (document.all) {
  alert(document.all['r2c1'].innerText);
  var row = 2;
  var column = 1;
  alert(document.all['r' + row + 'c' + column].innerText);
}
//--></script>

The following was submitted by alex ivetic

Important note: make sure that ID's of the row and columns are NOT numbers only, otherwise referencing them with document.all[row_id] won't work. (It's ok to do something like <TR ID="A1">...</TR>, but <TR ID="1">...</TR> will not work. I lost 5 hours trying to figure out why a piece of code is not working because of this!) I guess it javascript converts the string into number somehow even though you pass it to a function as a string.

Feedback on 'Q1601 Is there any way to retreive the text from a table cell based on its position in a table (e.g. cell 5,3)?'

©2018 Martin Webb