Link to home
Start Free TrialLog in
Avatar of rajikrishna
rajikrishna

asked on

Binding Array to a html table

I have a html table with few columns say

'Name' 'A' 'B' 'C' 'D'

I need to loop through each row of the table ,copy its contents to a javascript array which will hold the contents of all the columns of the table.
And it should work the other way round as well.
If i have an array i should be able to bind it to the table.

i used the follorwing function to loop through the table and collect its contents ,its working fine but i am getting a javscript error saying "cells is null or not an object" but i am getting the cell's contents in the alert box.
If XML can be used then also its fine.
If anybody has an idea kindly help me out

function ReadTable() {
var tbl = document.getElementById('myGrid');
var j;
            
for(j=0;j<=tbl.rows.length;j++) {
var row = tbl.rows[j];
alert(row.cells[1].innerText)
}
}

ASKER CERTIFIED SOLUTION
Avatar of r_a_j_e_s_h
r_a_j_e_s_h

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rajikrishna
rajikrishna

ASKER

ok how do i bind the array to the table and how to copy the contents of the table (row.cells[1].innerText) to an array??