Jump to content

Count Table Rows


ashleyfoozi

Recommended Posts

Hi Everybody I need to place the result of the code automatically into a text box and not be displayed as an alert after a button press.This code can be found all over the net and all, with variations, end up with a button and an alert. I am collecting, using a repeating table, data that is alphanumeric. The end result must show automatically in a text box seperate from the table.Any help is appreciated.

<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><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><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>

Link to comment
Share on other sites

The first thing you need to do is make that a valid page. A valid page only has 1 html element, 1 head, and 1 body. It looks like you have the same code duplicated 3 times, I don't know if that's just an error when you pasted the code or not. Put the text box on the page and give it an ID, and use document.getElementById to get the text box and use the value property to update the text in the box with whatever you want. http://www.w3schools.com/jsref/prop_text_value.asp

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...