Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Senior Coder crmpicco's Avatar
    Join Date
    Jan 2005
    Location
    Mauchline, Scotland
    Posts
    1,096
    Thanks
    15
    Thanked 1 Time in 1 Post

    count the number of rows in the table

    I would like to be able to write a function (or something) to count the number of rows in the table, I don't know how to do it, any help is appreciated.

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    var rowCount = document.getElementById("tableID").getElementsByTagName("TR").length;
    alert(rowCount);
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #3
    New Coder
    Join Date
    Apr 2011
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi,
    But this method throws a "Object Required" error and opening a new browser window.What can be the reason behind this?

    Thanks,
    Anil

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    Quote Originally Posted by anil029 View Post
    Hi,
    But this method throws a "Object Required" error and opening a new browser window.What can be the reason behind this?

    Thanks,
    Anil
    It works just fine for me.

    The fault, dear Brutus, lies not in the stars but .......

    It is your responsibility to die() if necessary….. - PHP Manual

  • #5
    Banned
    Join Date
    Feb 2011
    Posts
    2,699
    Thanks
    13
    Thanked 395 Times in 395 Posts
    Quote Originally Posted by crmpicco View Post
    I would like to be able to write a function (or something) to count the number of rows in the table, I don't know how to do it, any help is appreciated.
    Code:
    alert(document.getElementById('yourTableID').rows.length);

  • #6
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Quote Originally Posted by bullant View Post
    Code:
    alert(document.getElementById('yourTableID').rows.length);
    It absolutely the same as glenngv posted
    Code:
    alert(document.getElementById('yourTableID').getElementsByTagName('tr').length);
    Quote Originally Posted by anil029
    Hi,
    But this method throws a "Object Required" error and opening a new browser window.What can be the reason behind this?
    Impossible.

    Anyway, you have cross-posted:
    http://www.codingforums.com/showthread.php?t=223824
    So we should continue the discussion there. I will close this old thread, which was dug up for nothing
    Last edited by Kor; 04-12-2011 at 09:45 AM.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #7
    Banned
    Join Date
    Feb 2011
    Posts
    2,699
    Thanks
    13
    Thanked 395 Times in 395 Posts
    Quote Originally Posted by Kor View Post
    It absolutely the same as glenngv posted
    [code]
    Your statement is obviously not true, again

    It produces the same result but is not the same code I just offered another option to get what the op wants.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •