HI WELCOME TO KANSIRIS

Get a particular cell value from HTML table using JavaScript

Leave a Comment
To get the text from this cell-
<table>
    <tr id="somerow">
        <td>some text</td>            
    </tr>
</table>
You can use this -
var Row = document.getElementById("somerow");
var Cells = Row.getElementsByTagName("td");
alert(Cells[0].innerText);
or
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++) {
If( c == (particular cell number)){
            alert(table.rows[r].cells[c].innerHTML);
        }
     }
    }
}

0 comments:

Post a Comment

Note: only a member of this blog may post a comment.