Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
|
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 28th, 2005, 08:35 AM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default 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.


__________________
_______________________
Ayrshire Minis - a Mini E-Community
http://www.ayrshireminis.com
http://www.crmpicco.co.uk
 
Old January 28th, 2005, 01:13 PM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

http://msdn.microsoft.com/library/de...asp?frame=true

Look under DHTML Objects for table and look at its collections.

--

Joe (Microsoft MVP - XML)
 
Old January 28th, 2005, 04:33 PM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 290
Thanks: 24
Thanked 0 Times in 0 Posts
Default

Hi,

I have not tried this but I think that is the way to do it.

function getTables()
{
    var arrTables = document.getElementsById("tableID");
    var oRows = arrTables.rows;
    alert(oRows.length)
}

 
Old January 29th, 2005, 05:43 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Quote:
quote:Originally posted by pallone
     var arrTables = document.getElementsById("tableID");
=>
Code:
document.getElementById


--

Joe (Microsoft MVP - XML)
 
Old February 2nd, 2005, 12:58 AM
Friend of Wrox
 
Join Date: Dec 2004
Posts: 307
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Vadivel Send a message via Yahoo to Vadivel
Default

yep it works ... just tried out a sample and here is the code ...

<html>
<head>
<script language="javascript">
   function countTableRows()
   {
     var rows=document.getElementById("tbl").rows.length;
     alert(rows);
   }
</script>
</head>
<body>

<table id="tbl">
   <tr><td>Row 1</td></tr>
   <tr><td>Row 2</td></tr>
   <tr><td>Row 3</td></tr>
   <tr><td>Row 4</td></tr>
</table>
<input type="button" value="count" onClick="javascript:countTableRows()">

</body>
</html>

Best Regards
Vadivel

MVP ASP/ASP.NET
http://vadivel.thinkingms.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
Number of table rows to a variable Paula222 Access VBA 2 February 7th, 2006 09:33 AM
count of rows ashokparchuri ADO.NET 3 April 19th, 2005 11:19 AM
count child table rows melvik C# 6 January 25th, 2004 01:39 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.