Java script get table cell values and get cell text boxes values
How can I get table cell values and cells text boxes values?That means getting childNodes values using java script.This is easy using core javascripts.Only using 2 for loops.First loop is going to get rows by rows.And other for loop is going each colomn/cells while running the loop of row.This is easy to understand by following simple example.

This is my table.
| ID | Name | Country | Marks | Rank |
|---|---|---|---|---|
| 1 | Smith | US | 4 | |
| 2 | John | England | 2 | |
| 3 | William | Australia | 3 | |
| 4 | Michael | Germany | 1 |
Now we’ll get the values.
// Get table object
var myTable = document.getElementById('student_table').tBodies[0];
// first loop for each row
for (var r=0, n = myTable.rows.length; r < n; r++) {
// this loop is getting each colomn/cells
for (var c = 0, m = myTable.rows[r].cells.length; c < m; c++) {
if(myTable.rows[r].cells[c].childNodes[0].value){
// get student names
var StudentName = myTable.rows[r].cells[1].innerHTML;
alert(StudentName);
// get student marks in each text boxes
var marks = myTable.rows[r].cells[c].childNodes[0].value;
alert(marks);
}
}
}
That's only.
Additional Notes
Get table row count.
var rowCount = document.getElementById('student_table').tBodies[0].rows.length;
Get table column count.
var columnCount = document.getElementById('student_table').rows[0].cells.length;
Get table cell html.
var cellHtml = document.getElementById('student_table').tBodies[0].rows[r].cells.innerHTML;
Get table cell text.
var cellText = document.getElementById('student_table').tBodies[0].rows[r].cells.Text;
What's your reaction?
Excited
0
Happy
0
In Love
0
Not Sure
0
Silly
0





