locked
Uncaught TypeError: Cannot read property 'nodeValue' of undefined RRS feed

  • Question

  • User1283114192 posted

    assigning an nullable value in dynamic table row td

    for (var i = 0; i < creditNoteDetailTable.rows.length; i++) {
    var creditDetail = {
    "Id": 0,
    "SDAppValue": 0,
    "SDValue": 0,
    "VATValue": 0,
    "Quantity": 0,
    "TotalWithoutSD":0,
    };

    creditDetail.Id = parseInt(creditNoteDetailTable.rows[i].id);
    creditDetail.SDAppValue = isNaN(parseFloat(creditNoteDetailTable.rows[i].cells[2].childNodes[0].nodeValue)) ? 0 : parseFloat(creditNoteDetailTable.rows[i].cells[2].childNodes[0].nodeValue);
    creditDetail.SDValue = isNaN(parseFloat(creditNoteDetailTable.rows[i].cells[3].childNodes[0].nodeValue)) ? 0 : parseFloat(creditNoteDetailTable.rows[i].cells[3].childNodes[0].nodeValue);
    creditDetail.VATValue = isNaN(parseFloat(creditNoteDetailTable.rows[i].cells[4].childNodes[0].nodeValue)) ? 0 : parseFloat(creditNoteDetailTable.rows[i].cells[4].childNodes[0].nodeValue);
    creditDetail.Quantity = isNaN(parseFloat(creditNoteDetailTable.rows[i].cells[5].childNodes[0].nodeValue)) ? 0 : parseFloat(creditNoteDetailTable.rows[i].cells[5].childNodes[0].nodeValue);
    creditDetail.TotalWithoutSD = isNaN(parseFloat(creditNoteDetailTable.rows[i].cells[6].childNodes[0].nodeValue)) ? 0 : parseFloat(creditNoteDetailTable.rows[i].cells[6].childNodes[0].nodeValue);
    creditDetail.TotalSD = isNaN(parseFloat(creditNoteDetailTable.rows[i].cells[7].childNodes[0].nodeValue)) ? 0 : parseFloat(creditNoteDetailTable.rows[i].cells[7].childNodes[0].nodeValue);
    creditDetail.TotalVAT = isNaN(parseFloat(creditNoteDetailTable.rows[i].cells[8].childNodes[0].nodeValue)) ? 0 : parseFloat(creditNoteDetailTable.rows[i].cells[8].childNodes[0].nodeValue);
    creditDetail.IssueSD = isNaN(parseFloat(creditNoteDetailTable.rows[i].cells[9].childNodes[0].nodeValue)) ? 0 : 
    creditDetailList.push(finishedGoodsReceiveDetail);
    }

     

    Monday, August 29, 2016 3:12 PM

All replies

  • User-474980206 posted

    one of the childNodes[0] is null. most likely an empty <td>.

    Monday, August 29, 2016 4:27 PM
  • User1283114192 posted

    yeah, but how to solve it?

    my requirement is it may be null when adding but in edit it may have value.

    how to check is null?

    Tuesday, August 30, 2016 3:55 AM
  • User527778624 posted

    Hi,

    Try checking for childNodes using hasChildNodes() method, then you can check for it's nodeType (text or control).

    Check this site for details: http://www.w3schools.com/jsref/dom_obj_all.asp

    Tuesday, August 30, 2016 9:32 AM
  • User-474980206 posted

    yeah, but how to solve it?

    my requirement is it may be null when adding but in edit it may have value.

    how to check is null?

    test for null, a function would help:

    // test node exists & get value (force 0 if NaN or node is null)
    creditDetail.SDAppValue = creditNoteDetailTable.rows[i].cells[2].childNodes[0]
         ? parseFloat(creditNoteDetailTable.rows[i].cells[2].childNodes[0].nodeValue)) || 0
         : 0;
    
    // a function - assumes row and cell index valid
    function getValue(node) {
       return node 
           ? parseFloat(node.nodeValue)) || 0
           : 0;
    }
    creditDetail.SDAppValue = getValue(creditNoteDetailTable.rows[i].cells[2].childNodes[0]);
    
    

    note: much simpler and faster

       var float = parseFloat(value) || 0;

    for NaN test.

     

    Tuesday, August 30, 2016 7:21 PM
  • User1283114192 posted

    thanks bruce

    function getValue(node) {
    return node
    ? parseFloat(node.nodeValue)) || 0
    : 0;
    }
    this function works fine but I need to add childNodes in edit time

    Wednesday, August 31, 2016 5:13 AM
  • User1283114192 posted

    thanks raju dasa
    hasChildNodes() works fine but I need to add childNodes in edit time

    Wednesday, August 31, 2016 5:16 AM
  • User-1142886626 posted

    Hi jhsheikh,

    jhsheikh

    hasChildNodes() works fine but I need to add childNodes in edit time

    You could try using appendChild () Method, then you could append a child node.

    Check this site for details:

    http://www.w3schools.com/jsref/met_node_appendchild.asp

    Best Regards,

    Ailleen

    Tuesday, September 13, 2016 8:51 AM