0

First I wanna say that I'm new to javascript so this may look as a simple problem. I'm tring to extract data from a dynamically generated html table( table id ="tableId") using DOM. 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

1 Answer 1

1

You could do

var inputs = document.getElementById('tableID').getElementsByTagName('input');
for (var i = 0; i < inputs.length; i++) {
    alert(inputs[i].value);
}

text input fields (unless it's a textarea), don't really have a .nodeValue. The data entered into the form field is stored in .value.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.