homepage Welcome to WebmasterWorld Guest from 54.197.215.146
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Problems with javascript tables in Mozilla
napoleta




msg:4429636
 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

 

Fotiman




msg:4429642
 5:30 pm on Mar 15, 2012 (gmt 0)

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>

napoleta




msg:4429822
 8:35 am on Mar 16, 2012 (gmt 0)

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved