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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

determine number of columns in table data

Status
Not open for further replies.

cylly

Programmer
Oct 17, 2002
23
CA
How can I find out the number of columns in my table? The information is loaded dynamically. The number of columns will vary depending on what information was selected from a previous page.

Any help would be greatly appreciated.
 
Hi,

This might work for you. First, if it doesn't already have one, give your table a header row. If you don't want it to show up, use "display:none" to hide it from view. Then, for every element in your header row, give it an ID (in this example, "me"). Then the following JavaScript code will count the number of cells with the ID "me":

Code:
var x = document.getElementsByTagName("TD");
var i=0;
var cols = 0;
while(i<x.length) {
  if (x.item(i).id == 'me') { cols++; }
  i++;
}


I think you can do something simpler with getElementByID (check out but I couldn't get that working in the last fifteen minutes of work. ;)

Hope that helps,

Misty
 
thread216-424690 ---------------------------------------
{ str = &quot;sleep is good for you. sleep gives you the energy you need to function&quot;;
ptr = /sleep/gi;Nstr = str.replace(ptr,&quot;coffee&quot;);alert(Nstr); }

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top