Reading a table from a webpage

~ Б0ЯИ Τ0 С0δЭ ~
28Aug2009,18:36   #1
SaswatPadhi's Avatar
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ЯИ Τ0 С0δЭ ~
28Aug2009,21:02   #2
SaswatPadhi's Avatar
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 ... :)
}
Invasive contributor
29Aug2009,00:15   #3
nimesh's Avatar
yes, that's correct
Go4Expert Founder
29Aug2009,09:33   #4
shabbir's Avatar
getElementsByTagName is definitely an option but there are others like getElementById and getElementByClass
Light Poster
2Sep2009,14:12   #5
Saseydon's Avatar
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ЯИ Τ0 С0δЭ ~
2Sep2009,17:55   #6
SaswatPadhi's Avatar
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.