Monday, January 20, 2014

html table to JavaScript array

you can put data of HTML table to a array and then send it to PHP or JAVA or GROOVY for any use with following code. 
      

      var myTableArray = [];
            $("#dataTableList tr").each(function() {
                var arrayOfThisRow = [];
                var tableData = $(this).find('td');
                if (tableData.length > 0) {
                    tableData.each(function() { arrayOfThisRow.push($(this).text()); });
                    myTableArray.push(arrayOfThisRow);
                }
            });
            alert(myTableArray)

note here dataTableList is my table id

0 comments:

Post a Comment