dcsimg
www.webdeveloper.com
Results 1 to 3 of 3

Thread: Extracting data of a dynamic html table using DOM

  1. #1
    Join Date
    Nov 2011
    Posts
    2

    Question Extracting data of a dynamic html table using DOM

    Hi all,

    I'm using DOM in javascript to extract data from a dynamically generated html table( table id ="tableId"). Each cell of the table includes an input field to get user input. The problem is below javascript returns "null" always when retrieving the input field value? What I'm doing wrong here?


    var mytable = document.getElementById('tableId');
    var mytablebody = mytable.getElementsByTagName("tbody")[0];
    var myrow = mytablebody.getElementsByTagName("tr")[0];
    var cell = myrow.getElementsByTagName("td")[0];
    var inputNode = cell.childNodes[0];
    var taskName = inputNode.nodeValue; //???????

    document.write("Task Name:" + taskName);

    Thaks in Advance

  2. #2
    Join Date
    Oct 2010
    Location
    Versailles, France
    Posts
    1,276
    With several alerts, he must be possible to understand what takes place...
    White spaces (tabs or other line feeds) in cells, could give childNodes (*) ... A cell.childNodes.length() or the list of childNodes would be usefull to understand.

    (*) They are different type of node (with different browsers behaviours), you have probably to select only the node with tagName=='input' (or a nodeType==1).
    Last edited by 007Julien; 11-05-2011 at 08:32 AM.

  3. #3
    Join Date
    Nov 2011
    Posts
    2
    This works when last two lines are changed as below.

    var mytable = document.getElementById('tableId');
    var mytablebody = mytable.getElementsByTagName("tbody")[0];
    var myrow = mytablebody.getElementsByTagName("tr")[0];
    var cell = myrow.getElementsByTagName("td")[0];
    var cellchild = cell.getElementsByTagName("input")[0]; //
    var taskName = cellchild.value;//


    document.write("Task Name:" + taskName);

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles