Re: Querying a dynamically constructed html table
- From: Toby Inkster <usenet200511@xxxxxxxxxxxxxxxxx>
- Date: Tue, 29 Nov 2005 19:15:42 +0000
ukrbend wrote:
> Is there a way to do a client side query (perhaps using a scripting
> language) that allows you to query info about an html table that was
> constructed on the server side via ASP? So for instance how many rows
> and columns the table has.
<table id="foo" border="1">
<tr>
<td>A</td>
<td>B</td>
<td>C</td>
</tr>
<tr>
<td>Red</td>
<td>Blue</td>
<td>Green</td>
</tr>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
</tr>
</table>
<script type="text/javascript">
// grab our table and its rows.
var tabl = document.getElementById("foo");
var rows = tabl.getElementsByTagName("TR");
// count the number of rows
var number_of_rows = rows.length;
// columns is more tricky as each row may contain a
// different number of cells!
var number_of_cols = 0;
for (var i=0; rows[i]; i++)
{
var n = rows[i].getElementsByTagName("TD").length;
if (n > number_of_cols) number_of_cols = n;
}
// report our results
window.alert("foo has " + number_of_rows + " rows " +
"and " + number_of_cols + " cols.");
</script>
--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
.
- Follow-Ups:
- Re: Querying a dynamically constructed html table
- From: ukrbend
- Re: Querying a dynamically constructed html table
- References:
- Querying a dynamically constructed html table
- From: ukrbend
- Querying a dynamically constructed html table
- Prev by Date: Imposing my style *** on an IFRAME content.
- Next by Date: Re: Search Engine Tag?
- Previous by thread: Re: Querying a dynamically constructed html table
- Next by thread: Re: Querying a dynamically constructed html table
- Index(es):