Saturday, 15 July 2017

Table read with Java Script

This is how I consummate reading a table in javascript. Basically I study down into the rows and then I was able to drill down into the individual cells for each row. This should give you an idea.

Roll Name City
101 Sona Varanasi
102 Mona Chandauli
103 Amit Jaunpur

    <title>Girfa Student Help : Table read with javascript</title>
        function GetData()

            var oTable = document.getElementById('tbData');
            var label = document.getElementById('s1');
            //gets rows of table
            var rowLength = oTable.rows.length;

            //loops through rows   
            for (i = 0; i < rowLength; i++) {

                //gets cells of current row
                var oCells = oTable.rows.item(i).cells;

                //gets amount of cells of current row
                var cellLength = oCells.length;

                //loops through each cell in current row
                for (var j = 0; j < cellLength; j++) {
                    /* get your cell info here */
                     label.innerHTML+= oCells.item(j).innerHTML + " | ";
    <h1 align="center">Table Data Read With Java Script</h1><hr />
    <table border="1" id="tbData" cellspacing="0" cellpadding="5">
    </table><br />
    <input type="button" value="Read" onclick="GetData()" /><br /><br />
    <span id="s1"></span>


No comments:

Post a Comment