Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1610
  • Last Modified:

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)
}
}

0
rajikrishna
Asked:
rajikrishna
1 Solution
 
r_a_j_e_s_hCommented:
function ReadTable() {
var tbl = document.getElementById('myGrid');
var j;
         
for(j=0;j<tbl.rows.length;j++) {
             ^------------------->change here
var row = tbl.rows[j];
alert(row.cells[1].innerText)
}
}




0
 
rajikrishnaAuthor Commented:
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??
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now