Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

Problems with javascript tables in Mozilla

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

New User

joined:Mar 15, 2012
votes: 0

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:


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?
5:30 pm on Mar 15, 2012 (gmt 0)

Senior Member from US 

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

joined:Oct 17, 2005
posts: 4966
votes: 10

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>
<table id="myTable">
<td>Row 1, Col 1</td>
<td>Row 1, Col 2</td>
<td>Row 2, Col 1</td>
<td>Row 2, Col 2</td>
var i,
table = document.getElementById('myTable'),
rows = table.getElementsByTagName('tr'),
// 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;
8:35 am on Mar 16, 2012 (gmt 0)

New User

joined:Mar 15, 2012
votes: 0

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