Reading a table from a webpage

SaswatPadhi's Avatar, Join Date: May 2009
~ Б0ЯИ Τ0 С0δЭ ~
Hi all,

I want to read a table from a web page and populate something else with those data.
I can access the whole table by it's Id, which is known.
So, I do something like :
Code: JavaScript
var myTable = document.getElementById("Table_A");

Now, how can I read the data in the different rows and columns and use them ?

Thanx in advance
0
SaswatPadhi's Avatar, Join Date: May 2009
~ Б0ЯИ Τ0 С0δЭ ~
OK. I finally got it
To help other members who might face the same problem in future, I am posting my solution here :

The only thing that saves us in this situation is "getElementsByTagName".
So, you can do it like this :

Code: JavaScript
// get the table.
var myTable = document.getElementById("Table_A");
// get all rows inside the table
var allRows = myTable.getElementsByTagName("TR");
// variables to store all cells in a row
var allCells;

for(var x=0; x < allRows.length; ++x)
{
    // get all the cells in row x
    allCells = allRows[x].getElementsByTagName("TD");
   
    // do whatever you like ... :)
}
0
nimesh's Avatar, Join Date: Apr 2009
Invasive contributor
yes, that's correct
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
getElementsByTagName is definitely an option but there are others like getElementById and getElementByClass
0
Saseydon's Avatar, Join Date: May 2009
Light Poster
I consider, that you are not right. I can prove it. Write to me in PM, we will communicate.

Last edited by shabbir; 2Sep2009 at 18:47.. Reason: Confine links to signatures only
0
SaswatPadhi's Avatar, Join Date: May 2009
~ Б0ЯИ Τ0 С0δЭ ~
Quote:
Originally Posted by Saseydon View Post
I consider, that you are not right. I can prove it. Write to me in PM, we will communicate.
OK. May be I am wrong.
But why PM ???

Share your thoughts here. Everyone will be benefited.