Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Web Design, HTML And CSS Forums (http://www.go4expert.com/forums/web-design-forum/)
-   -   Reading a table from a webpage (http://www.go4expert.com/forums/reading-table-webpage-t19211/)

SaswatPadhi 28Aug2009 18:36

Reading a table from a webpage
 
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 :)

SaswatPadhi 28Aug2009 21:02

Re: Reading a table from a webpage
 
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 ... :)
}


nimesh 29Aug2009 00:15

Re: Reading a table from a webpage
 
yes, that's correct

shabbir 29Aug2009 09:33

Re: Reading a table from a webpage
 
getElementsByTagName is definitely an option but there are others like getElementById and getElementByClass

Saseydon 2Sep2009 14:12

Reading a table from a webpage
 
I consider, that you are not right. I can prove it. Write to me in PM, we will communicate.

SaswatPadhi 2Sep2009 17:55

Re: Reading a table from a webpage
 
Quote:

Originally Posted by Saseydon (Post 56668)
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. :)


All times are GMT +5.5. The time now is 02:44.