1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

Reading a table from a webpage

Discussion in 'Web Design, HTML And CSS Forums' started by SaswatPadhi, Aug 28, 2009.

  1. SaswatPadhi

    SaswatPadhi ~ Б0ЯИ Τ0 С0δЭ ~

    Joined:
    May 5, 2009
    Messages:
    1,343
    Likes Received:
    55
    Trophy Points:
    0
    Occupation:
    STUDENT !
    Location:
    Orissa, INDIA
    Home Page:
    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:
    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 :)
     
  2. SaswatPadhi

    SaswatPadhi ~ Б0ЯИ Τ0 С0δЭ ~

    Joined:
    May 5, 2009
    Messages:
    1,343
    Likes Received:
    55
    Trophy Points:
    0
    Occupation:
    STUDENT !
    Location:
    Orissa, INDIA
    Home Page:
    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:
    // 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 ... :)
    }
    
     
  3. nimesh

    nimesh New Member

    Joined:
    Apr 13, 2009
    Messages:
    770
    Likes Received:
    20
    Trophy Points:
    0
    Occupation:
    Oracle Apps Admin
    Location:
    Mumbai
    Home Page:
    yes, that's correct
     
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,276
    Likes Received:
    364
    Trophy Points:
    83
    getElementsByTagName is definitely an option but there are others like getElementById and getElementByClass
     
  5. Saseydon

    Saseydon New Member

    Joined:
    May 20, 2009
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Czech Republic
    Location:
    Czech Republic
    I consider, that you are not right. I can prove it. Write to me in PM, we will communicate.
     
    Last edited by a moderator: Sep 2, 2009
  6. SaswatPadhi

    SaswatPadhi ~ Б0ЯИ Τ0 С0δЭ ~

    Joined:
    May 5, 2009
    Messages:
    1,343
    Likes Received:
    55
    Trophy Points:
    0
    Occupation:
    STUDENT !
    Location:
    Orissa, INDIA
    Home Page:
    OK. May be I am wrong.
    But why PM ???

    Share your thoughts here. Everyone will be benefited. :)
     

Share This Page