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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bgraphics2031
    New Member
    • May 2007
    • 12

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

    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:

    Code:
    function TableResize_GetFirstColumnCell(objTable, iCellIndex)
    {
    	var oHeaderCell = objTable.rows[0].cells[iCellIndex];
    	return oHeaderCell;
    	
    }
  • mrhoo
    Contributor
    • Jun 2006
    • 428

    #2
    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:


    Code:
    var cell1= document.body.getElementsByTagName('table')[0].getElementsByTagName('tr')[0].getElementsByTagName('*')[0];

    This is not restricted to firefox- any modern dom aware browser can use it.

    Comment

    • bgraphics2031
      New Member
      • May 2007
      • 12

      #3
      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:

      Code:
      function TableResize_GetFirstColumnCell(objTable, cellIndex)
      {
      	var oHeaderCell = document.body.getElementsByTagName('table')[0].getElementsByTagName('tr')[0].getElementsByTagName('*')[0];
      	return oHeaderCell;
      }
      But when I try to get the value later I get that it's undefined.

      Code:
      function TableResize_OnMouseDown(objTable, event)
      {
      	var oTargetCell = event.currentTarget;
      	//alert(oTargetCell);
      	
      	if(!oTargetCell)
      		return;
      	
      	if(oTargetCell.parentNode.tagName.toUpperCase() == sResizableElement)
      	{
      		oTargetCell = oTargetCell.parentNode;
      		
      	}
      	//THIS PART HERE IS UNDEFINED;
      	var oHeaderCell = TableResize_GetFirstColumnCell(objTable, oTargetCell.cellIndex);
      	//alert(oTargetCell.cellIndex);
      		
      	if((oHeaderCell.tagName.toUpperCase() == sResizableElement) && (oTargetCell.style.cursor == "e-resize"))
      	{
      		iStartX = event.screenX;
      		oResizeTarget = oHeaderCell;
      		objTable.setAttribute("Resizing","true");
      		//Set Capture?
      		
      		oVBar.style.left = document.body.scrollLeft - document.body.clientLeft;
      		oVBar.style.top = objTable.parentNode.offsetTop + objTable.offsetTop;
      		oVBar.style.height = objTable.parentNode.offsetHeight;
      		oVBar.style.display = "inline";
      	}
      	//alert(document.body.scrollLeft - document.body.clientLeft);
      	return true;
      }
      Can you help me?

      Comment

      • mrhoo
        Contributor
        • Jun 2006
        • 428

        #4
        Code:
        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.

        Code:
        tc=[B]objTable[/B].getElementsByTagName('tr')[0].getElementsByTagName('*')[[B]cellIndex[/B]];
        Last edited by acoder; May 14 '07, 05:19 PM. Reason: Added code tags

        Comment

        • acoder
          Recognized Expert MVP
          • Nov 2006
          • 16032

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

          Comment

          • bgraphics2031
            New Member
            • May 2007
            • 12

            #6
            Originally posted by mrhoo
            Code:
            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.

            Code:
            tc=[B]objTable[/B].getElementsByTagName('tr')[0].getElementsByTagName('*')[[B]cellIndex[/B]];
            Firefox throws a "cellIndex is not defined" in the error console. Thanks anyways.

            Comment

            • iam_clint
              Recognized Expert Top Contributor
              • Jul 2006
              • 1207

              #7
              before that line of code put

              cellindex = 1

              or cellindex = 2 or whatever you want

              Comment

              • acoder
                Recognized Expert MVP
                • Nov 2006
                • 16032

                #8
                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!

                Comment

                • bgraphics2031
                  New Member
                  • May 2007
                  • 12

                  #9
                  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.

                  Comment

                  Working...