Posted by Toby Inkster on 11/29/05 21:15
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
Navigation:
[Reply to this message]
|