Reading a table from a webpage

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

  1. SaswatPadhi

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

    Joined:
    May 5, 2009
    Messages:
    1,342
    Likes Received:
    55
    Trophy Points:
    0
    Occupation:
    STUDENT !
    Location:
    Orissa, INDIA
    Home Page:
    http://www.crackingforfun.blogspot.com
    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,342
    Likes Received:
    55
    Trophy Points:
    0
    Occupation:
    STUDENT !
    Location:
    Orissa, INDIA
    Home Page:
    http://www.crackingforfun.blogspot.com
    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:
    769
    Likes Received:
    20
    Trophy Points:
    0
    Occupation:
    Oracle Apps Admin
    Location:
    Mumbai
    Home Page:
    http://techiethakkar.blogspot.com
    yes, that's correct
     
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    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,342
    Likes Received:
    55
    Trophy Points:
    0
    Occupation:
    STUDENT !
    Location:
    Orissa, INDIA
    Home Page:
    http://www.crackingforfun.blogspot.com
    OK. May be I am wrong.
    But why PM ???

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

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice