-1

I'm using this function to write the values from a dynamic table. I call it dyanmic because is possible to add and remove new lines.

    function GetCellValues() {
    var table = document.getElementById('mytable');
    for (var r = 0, n = table.rows.length; r < n; r++) {
        for (var c = 0, m = table.rows[r].cells.length; c < m; c++) {
            alert(table.rows[r].cells[c].children[0].value);
        }
    }
}

But if I change alert for document.write only the first cell value.

any suggestion?

Regards

putvande
  • 15,068
  • 3
  • 34
  • 50
  • 1
    Calling [`document.write()`](https://developer.mozilla.org/en-US/docs/Web/API/document.write) after the page has been parsed, will wipe out all previous code from the document, and open a new document. Don't use it. – Teemu Nov 29 '13 at 18:40

1 Answers1

0

document.write overwrites the entire document. So it stands that the first iteration picks up what you're looking for and anything after that doesn't know what you're talking about since its been overwritten.

Suggestion: DONT use document.write -- instead write to an existing element on the page.

tymeJV
  • 103,943
  • 14
  • 161
  • 157