Muggy Ate
Muggy Ate

Reputation: 343

Javascript outputs in a table

I had a friend figure out my problem for me last time and now I'm running into a different problem with Javascript. You see the script that I'm running is going to be happening AFTER the page loaded and I'm sorry if this question has been answered already, but basically I have a table and in each cell of the table, it contains some Javascript that fetches some data does something with it and returns either "live" or "offline". The problem is the page is already loaded at this point and if I use document.write it overwrites the whole page. I don't want that; I just want the world "live" or "offline" to be in the cell that called the function and I'm not sure how to do that.

To be a bit more clear I have a table and lets say in cell (1,1). I call a function x and inside function x and I get a result. I want to print the results in cell (1,1) and keep the result only in cell (1,1). How do I do that with Javascript AFTER the page has already loaded?

Upvotes: 1

Views: 164

Answers (1)

Christophe
Christophe

Reputation: 28114

Let's say your table has an id "tableId". You can access cell(i,j) this way:

var myTable=document.getElementById("tableId");
// an example: first row, second column
var i=0, j=1;
myTable.rows[i].cells[j].innerHTML= "live";

Note that the indexes start at 0.

Upvotes: 2

Related Questions