Connecting Tech Pros Worldwide Forums | Help | Site Map

Finding a cell in the first row of a table in Firefox

Newbie
 
Join Date: May 2007
Posts: 12
#1: May 10 '07
Hi all, just wanted to verify if this is the correct code for FF. I'm trying to find a cell at column iCellIndex in the first row of the table. I get that oHeaderCell is undefined. Thanks in advance, I must be too tired to catch any syntax errors, but here it is:

Expand|Select|Wrap|Line Numbers
  1. function TableResize_GetFirstColumnCell(objTable, iCellIndex)
  2. {
  3.     var oHeaderCell = objTable.rows[0].cells[iCellIndex];
  4.     return oHeaderCell;
  5.  
  6. }
Needs Regular Fix
 
Join Date: Jun 2006
Posts: 424
#2: May 11 '07

re: Finding a cell in the first row of a table in Firefox


there are row and cell objects, but it seems simpler to use ordinary dom methods-
the first cell in the first row of the first table on a page would be:


Expand|Select|Wrap|Line Numbers
  1. var cell1= document.body.getElementsByTagName('table')[0].getElementsByTagName('tr')[0].getElementsByTagName('*')[0];
  2.  

This is not restricted to firefox- any modern dom aware browser can use it.
Newbie
 
Join Date: May 2007
Posts: 12
#3: May 13 '07

re: Finding a cell in the first row of a table in Firefox


Thank you for answer my question mrhoo. I'm really unfamiliar with javascript and the dom and I have another question if you don't mind.

I changed the code to find the cell:

Expand|Select|Wrap|Line Numbers
  1. function TableResize_GetFirstColumnCell(objTable, cellIndex)
  2. {
  3.     var oHeaderCell = document.body.getElementsByTagName('table')[0].getElementsByTagName('tr')[0].getElementsByTagName('*')[0];
  4.     return oHeaderCell;
  5. }
But when I try to get the value later I get that it's undefined.

Expand|Select|Wrap|Line Numbers
  1. function TableResize_OnMouseDown(objTable, event)
  2. {
  3.     var oTargetCell = event.currentTarget;
  4.     //alert(oTargetCell);
  5.  
  6.     if(!oTargetCell)
  7.         return;
  8.  
  9.     if(oTargetCell.parentNode.tagName.toUpperCase() == sResizableElement)
  10.     {
  11.         oTargetCell = oTargetCell.parentNode;
  12.  
  13.     }
  14.     //THIS PART HERE IS UNDEFINED;
  15.     var oHeaderCell = TableResize_GetFirstColumnCell(objTable, oTargetCell.cellIndex);
  16.     //alert(oTargetCell.cellIndex);
  17.  
  18.     if((oHeaderCell.tagName.toUpperCase() == sResizableElement) && (oTargetCell.style.cursor == "e-resize"))
  19.     {
  20.         iStartX = event.screenX;
  21.         oResizeTarget = oHeaderCell;
  22.         objTable.setAttribute("Resizing","true");
  23.         //Set Capture?
  24.  
  25.         oVBar.style.left = document.body.scrollLeft - document.body.clientLeft;
  26.         oVBar.style.top = objTable.parentNode.offsetTop + objTable.offsetTop;
  27.         oVBar.style.height = objTable.parentNode.offsetHeight;
  28.         oVBar.style.display = "inline";
  29.     }
  30.     //alert(document.body.scrollLeft - document.body.clientLeft);
  31.     return true;
  32. }
Can you help me?
Needs Regular Fix
 
Join Date: Jun 2006
Posts: 424
#4: May 13 '07

re: Finding a cell in the first row of a table in Firefox


Expand|Select|Wrap|Line Numbers
  1. tc=document.body.getElementsByTagName('table')[0].getElementsByTagName('tr')[0].getElementsByTagName('*')[0];
The code I gave you was to find the first cell in the first row of the first table on a page. I guess I was hoping you would be able to extend it yourself.

Expand|Select|Wrap|Line Numbers
  1. tc=objTable.getElementsByTagName('tr')[0].getElementsByTagName('*')[cellIndex];
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#5: May 14 '07

re: Finding a cell in the first row of a table in Firefox


Sorry mrhoo, I had to add code tags to your post because it was messing up the formatting on the page.
Newbie
 
Join Date: May 2007
Posts: 12
#6: May 14 '07

re: Finding a cell in the first row of a table in Firefox


Quote:

Originally Posted by mrhoo

Expand|Select|Wrap|Line Numbers
  1. tc=document.body.getElementsByTagName('table')[0].getElementsByTagName('tr')[0].getElementsByTagName('*')[0];
The code I gave you was to find the first cell in the first row of the first table on a page. I guess I was hoping you would be able to extend it yourself.

Expand|Select|Wrap|Line Numbers
  1. tc=objTable.getElementsByTagName('tr')[0].getElementsByTagName('*')[cellIndex];

Firefox throws a "cellIndex is not defined" in the error console. Thanks anyways.
iam_clint's Avatar
Forum Leader
 
Join Date: Jul 2006
Location: Oklahoma
Posts: 1,076
#7: May 14 '07

re: Finding a cell in the first row of a table in Firefox


before that line of code put

cellindex = 1

or cellindex = 2 or whatever you want
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#8: May 15 '07

re: Finding a cell in the first row of a table in Firefox


Quote:

Originally Posted by acoder

Sorry mrhoo, I had to add code tags to your post because it was messing up the formatting on the page.

Drats, the new code tags have messed up the formatting anyway!
Newbie
 
Join Date: May 2007
Posts: 12
#9: May 15 '07

re: Finding a cell in the first row of a table in Firefox


Quote:

Originally Posted by iam_clint

before that line of code put

cellindex = 1

or cellindex = 2 or whatever you want

Thanks iam_clint, i got it working now.
Reply


Similar JavaScript / Ajax / DHTML bytes