Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Return number of rows in HTML TABLE

Status
Not open for further replies.

MrPeds

Programmer
Jan 7, 2003
219
GB
Hi,

I am a newbie to JavaScript so please bear with me.

I have 2 related questions please.

1) Is there a simple way of returning the number of rows in an html table in a JavaScript function?

2) If I have an HTML table looking a bit like this:

Name Date Comment
Fred 2006-10-11 some comment
Bob 2006-10-11 another comment
Fred 2006-10-12 foo bar

Is there any way of returning the number of rows in the html table for a given Name, e.g. where Name = 'Fred' ?

ANy help is appreciated.

Thanks,

Peds
 
1) this is easy:

Code:
var myTable = document.getElementById("myTableId");
alert(myTable.rows.length;

2) this would require some looping through the rows, retrieving the first table cell within the row, checking the innerHTML of that cell, then incrementing a counter.



*cLFlaVA
----------------------------
[tt]"quote goes here"[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top