Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12
  1. #1
    New Coder
    Join Date
    Jun 2013
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    cells.0 is null or not an object in IE7,IE9 and IE10

    --------------------------------------------------------------------------------

    Hi,

    I am having issue with a piece of javascript code across different internet explorer versions.

    The functionality is to add rows to a table on click of a button using javascript.


    This works fine in IE8 but fails in IE7,9 and IE10.

    The issue is with cells[0]-says cells.0 is null or not an object.
    Below is the piece of javascript code.

    var datatableObject=document.getElementById("view<portlet:namespace/>:form1:tblquickadd");
    var rowObj = datatableObject.tBodies[0].firstChild.cloneNode(true);
    rowObj.cells[0].getElementsByTagName("INPUT")[6]

    Please let me know if anybody has clue on this and what can work across browsers.

    Thanks
    Omkar

  • #2
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,296
    Thanks
    13
    Thanked 345 Times in 341 Posts
    if rowObj.cells were empty, that’s the expected error message.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • #3
    New Coder
    Join Date
    Jun 2013
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    But same functionality works fine in IE8 for same set of data too..Doesnt work in IE7 ,IE9 and IE10

  • #4
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,296
    Thanks
    13
    Thanked 345 Times in 341 Posts
    that’s no reason to not start debugging.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • #5
    New Coder
    Join Date
    Jun 2013
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I go a fix for this in IE7 by appending first and then assigning the rows but cells[0] still fails in IE9 and IE10.


    Notice the appendChild below in code..
    Code:
    var datatableObject=document.getElementById("view<portlet:namespace/>:form1:tblquickadd");
    
    var rowObj = datatableObject.tBodies[0].firstChild.cloneNode(true);
    datatableObject.tBodies[0].appendChild(rowObj);
    rowObj.cells[0].getElementsByTagName("INPUT")[6]
    Let me know what is the best way i can debug this out??

    Thanks
    Omkar

  • #6
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,296
    Thanks
    13
    Thanked 345 Times in 341 Posts
    console.log(rowObj) (or the IE-equivalent thereof)
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • #7
    New Coder
    Join Date
    Jun 2013
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    rowObj gives [ObjectText] in an alert box.

    rowObj.cells[0] breaks in alert.

    Postiing some more code
    [CODE]
    if(rowObj.cells[0].getElementsByTagName("INPUT")[6] && rowObj.cells[0].getElementsByTagName("INPUT")[7]){
    rowObj.cells[0].getElementsByTagName("INPUT")[6].value="0";
    rowObj.cells[0].getElementsByTagName("INPUT")[7].value="0";
    }


    rowObj.cells[0].getElementsByTagName("INPUT")[0].id = "view<portlet:namespace/>:form1:tblquickadd:"+rownum+":quickAddLineItemSelected";
    rowObj.cells[0].getElementsByTagName("INPUT")[0].checked=false;
    rowObj.cells[0].className="quickAddCol1 cahTableCellBorderNew_barcode";
    //alert("Style"+rowObj.cells[0].align);
    rowObj.cells[0].align="center";
    //alert("Style"+rowObj.cells[0].align);

    rowObj.cells[1].getElementsByTagName("INPUT")[0].id = "view<portlet:namespace/>:form1:tblquickadd:"+rownum+":quantityinputid";
    rowObj.cells[1].getElementsByTagName("INPUT")[0].value=z;
    rowObj.cells[1].className="quickAddCol2 cahTableCellBorderNew_barcode";
    rowObj.cells[1].align="center";

    [\CODE]

  • #8
    New Coder
    Join Date
    Jun 2013
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    rowObj gives [Object Text] in an alert box.

    rowObj.cells[0] breaks in alert.

    Postiing some more code
    Code:
    if(rowObj.cells[0].getElementsByTagName("INPUT")[6] && rowObj.cells[0].getElementsByTagName("INPUT")[7]){
    rowObj.cells[0].getElementsByTagName("INPUT")[6].value="0";
    rowObj.cells[0].getElementsByTagName("INPUT")[7].value="0";
    }
    
    
    rowObj.cells[0].getElementsByTagName("INPUT")[0].id = "view<portlet:namespace/>:form1:tblquickadd:"+rownum+":quickAddLineItemSelected";
    rowObj.cells[0].getElementsByTagName("INPUT")[0].checked=false;
    rowObj.cells[0].className="quickAddCol1 cahTableCellBorderNew_barcode";
    //alert("Style"+rowObj.cells[0].align);
    rowObj.cells[0].align="center";
    //alert("Style"+rowObj.cells[0].align);
    
    rowObj.cells[1].getElementsByTagName("INPUT")[0].id = "view<portlet:namespace/>:form1:tblquickadd:"+rownum+":quantityinputid";
    rowObj.cells[1].getElementsByTagName("INPUT")[0].value=z;
    rowObj.cells[1].className="quickAddCol2 cahTableCellBorderNew_barcode";
    rowObj.cells[1].align="center";

  • #9
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,296
    Thanks
    13
    Thanked 345 Times in 341 Posts
    Quote Originally Posted by omkargit101 View Post
    rowObj gives [Object Text] in an alert box.
    this tells us that rowObj is not a row object (that would show [object HTMLTableRowElement]), but a Text Node (part of the DOM interface). Text Nodes do not have a .cells property (returning undefined) and calling [0] on undefined throws an error.

    the problem is that the .firstChild call in IE has lately been fixed to match the behaviour of all other browsers (whitespace between elements counts as a separate text node, while IE has been discarding that for certain elements). if supported, use the .firstElementChild call (or make a workaround for it (e.g.) going through .childNodes until you hit an element child).
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • #10
    New Coder
    Join Date
    Jun 2013
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for that..I got similar suggestion on one more site..I am exploring it on how to apply firstElementChild.Its bit confusing for me

  • #11
    Senior Coder Arbitrator's Avatar
    Join Date
    Mar 2006
    Location
    Splendora, Texas, United States of America
    Posts
    3,302
    Thanks
    28
    Thanked 276 Times in 270 Posts
    Quote Originally Posted by omkargit101 View Post
    Thanks for that..I got similar suggestion on one more site..I am exploring it on how to apply firstElementChild.Its bit confusing for me
    Because you're looking for a specific type of element (tr), use of firstElementChild is unnecessary here. Change this line of code...

    Code:
    var rowObj = datatableObject.tBodies[0].firstChild.cloneNode(true);
    ... to this code...

    Code:
    var rowObj = datatableObject.tBodies[0].rows[0].cloneNode(true);
    For every complex problem, there is an answer that is clear, simple, and wrong.

  • #12
    New Coder
    Join Date
    Jun 2013
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks a lot..that works


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •