Welcome to WebmasterWorld Guest from 54.147.217.76

Forum Moderators: open

Message Too Old, No Replies

Problems with javascript tables in Mozilla

   
5:10 pm on Mar 15, 2012 (gmt 0)



Hello,
I am having poblems trying and modifying an HTML table from javascript with Mozilla, not with IE.
I have an html table where each row is identifyed by an id like this:

<tr id="row">

the table has n rows and m columns. From javascript I try and modify any cell in the table like this:

row(i).cells(j).innerHTML=value

where i is the cell row and j is the cell column. I would like to set the cell to value.

Mozilla does not change the cell, while in IE I do get the cell changed.

Anybody can help?
Thanks
Mino
5:30 pm on Mar 15, 2012 (gmt 0)

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



Welcome to WebmasterWorld.
Since you seem be accessing the rows and columns by index, I don't see how the row id applies in your example. You haven't really provided enough useful code.

Here's a quick example I put together which may be of help to you:

<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<table id="myTable">
<tr>
<td>Row 1, Col 1</td>
<td>Row 1, Col 2</td>
</tr>
<tr>
<td>Row 2, Col 1</td>
<td>Row 2, Col 2</td>
</tr>
</table>
<script>
var i,
table = document.getElementById('myTable'),
rows = table.getElementsByTagName('tr'),
cells;
// Iterate over each row
for (i = 0; i < rows.length; i++) {
// For each row, get the list of cells
cells = rows[i].getElementsByTagName('td');
// Iterate over the list of cells
for (j = 0; j < cells.length; j++) {
// Assign a new value to each cell
// For this example, I'm just prepending [i, j] (where i = row and j = col)
cells[j].innerHTML = "[" + i + ", " + j + "] " + cells[j].innerHTML;
}
}
</script>
</body>
</html>
8:35 am on Mar 16, 2012 (gmt 0)



It works both in Mozilla and IE, thanks a lot for your help!