How do I pull data (string) from a column called "Limit" in a table ("displayTable") in Javascript?
var table = document.getElementById('displayTable'); var rowCount = table.rows.length; for (var i = 1; i < rowCount - 1; i++) { var row = table.rows[i]["Limit"].ToString(); alert(row); ... }
SELECT statements An SQL SELECT statement retrieves records from a database table according to clauses (for example, FROM and WHERE ) that specify criteria. The syntax is: SELECT column1, column2 FROM table1, table2 WHERE column2='value';
This is how I accomplished reading a table in javascript. Basically I drilled 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
//gets table var oTable = document.getElementById('myTable'); //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 */ /* var cellVal = oCells.item(j).innerHTML; */ } }
UPDATED - TESTED SCRIPT
<table id="myTable"> <tr> <td>A1</td> <td>A2</td> <td>A3</td> </tr> <tr> <td>B1</td> <td>B2</td> <td>B3</td> </tr> </table> <script> //gets table var oTable = document.getElementById('myTable'); //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 var cellVal = oCells.item(j).innerHTML; alert(cellVal); } } </script>
in this code data
is a two dimensional array of table data
let oTable = document.getElementById('datatable-id'); let data = [...oTable.rows].map(t => [...t.children].map(u => u.innerText))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With