Using for loop to get table data

Related searches

I want to use a for loop to get a table for 6 rows. How can i use for loop to create a table to show the data that i want to show? I need to display a table showing the data on the right side of the table but i can't get it.

This is my code for html:

<div id="yr" class="year"></div>

This is my code for js:

    function repayment() {
        var x = document.getElementById("yr");
        if (x.style.display === "none") {
            x.style.display = "block";
        } else {
            x.style.display = "none";
        }

        var test, tr;

        test = '<table border="1px"><thead><tr><th> Year</th ></tr> <tr><th>' 
             + 'Month</th ></tr>  <tr><th>Repayment</th ></tr> <tr><th>Interest</th ></tr>' 
             + '<tr>' 
             + '<th>Loan Paid</th ></tr> <tr><th>Loan Balance</th ></tr></thead><tbody>';
        tr = '';
        for (var i = 0; i < 4; i++) {
            tr += '<tr>' + '<tr>';
            for (var j = 0; j < 4; j++) {
                tr += '<td>' + 12;
            }
        }
        tr += '</tr>';
        test += tr;
        return document.getElementById('yr').innerHTML = test;
    }
    repayment();

My results when i click the button :

Instead of

            test = '<table border="1px"><thead><tr><th> Year</th ></tr> <tr><th>' 
                 + 'Month</th ></tr>  <tr><th>Repayment</th ></tr> <tr><th>Interest</th ></tr>' 
                 + '<tr>' 
                 + '<th>Loan Paid</th ></tr> <tr><th>Loan Balance</th ></tr></thead><tbody>';

use

            test = '<table border="1px">'
                   + '<thead>'
                     + '<tr>'
                       + '<th>Year</th>'
                       + '<th>Month</th>
                       + '<th>Repayment</th>'
                       + '<th>Interest</th>'
                       + '<th>Loan Paid</th>'
                       + '<th>Loan Balance</th>'
                     + '</tr>'
                   + '</thead>'
                   + '<tbody>';

Loop Through Each HTML Table Column and Get the Data using , Using a nested .each() means that your inner loop is doing one td at a time, so you can't set the productId and product and quantity all in the� The table has three column: country_code, product, and unit price. (Note: I used the Mockaroo online data generator so it might happen there are duplicated rows.) Some basic example of referring to a column range of a table in different manners in VBA: one column excluding header: Range(“tbl_grocery[country_code]”) Range(table_name[column

The problem is with this line '<table border="1px"><thead><tr><th> Year</th ></tr> <tr><th>Month</th ></tr> <tr><th>Repayment</th ></tr> <tr><th>Interest</th ></tr><tr> + '<th>Loan Paid</th ></tr> <tr><th>Loan Balance</th ></tr></thead><tbody>'.

With every td you are closing the row using </tr>/ So it will create new rows.

An alternative & clean solution is to use template literals and create rows in a separate function

function repayment() {
  var x = document.getElementById("yr");
  if (x.style.display === "none") {
    x.style.display = "block";
  } else {
    //x.style.display = "none";
  }

  var test, tr;

  test =
    `<table border="1px">
         <thead>
          <tr>
            <th>Year</th>
            <th>Month</th>
            <th>Repayment</th>
            <th>Interest</th>
            <th> Loan Paid </th>
            <th> Loan Balance </th>
            </tr>
          </thead>
          <tbody>${createRows()}</tbody>
    </table>`;
  document.getElementById("yr").innerHTML = test;
}
repayment();

function createRows() {
  let tr = '';
  for (var i = 0; i < 4; i++) {
    tr += '<tr>' + '<tr>';
    for (var j = 0; j < 6; j++) {
      tr += '<td>' + 12;
    }
  }
  return tr;

}
<div id="yr" class="year"></div>

access data in table using for loop - MATLAB Answers, Learn more about access data from table, company ticker, for loop This will get a lot worse when dealing with more tickers - for example think� Pros and Cons of Using a While Loop to Iterate Through Table Rows in SQL Server. There are also benefits to use a WHILE loop compared to a cursor. While loops are faster than cursors. While loops use less locks than cursors. Less usage of Tempdb: While loops don’t create a copy of data in tempdb as a cursor does. Remember that cursors

$(document).ready(function(){
  repayment();
});



function repayment() {
        var x = document.getElementById("yr");
        if (x.style.display === "none") {
            x.style.display = "block";
        } else {
            x.style.display = "none";
        }

        var test, tr;

        test = '<table border="1px"> <thead> <tr> <th>Year</th> <th>Month</th> <th>Repayment</th> <th>Interest</th> <th>Loan Paid</th> <th>Loan Balance</th> </tr> </thead> <tbody>';
        tr = '';
        for (var i = 0; i < 4; i++) {
            tr += '<tr>' + '<tr>';
            for (var j = 0; j < 6; j++) {
                tr += '<td>' + 12;
            }
        }
        tr += '</tr>';
        test += tr;
        return document.getElementById('yr').innerHTML = test;
    }
    repayment();
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>APTARA</title>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
    </head>

    <body>
        <div id="yr" class="year"></div>
        
        <script src="script.js"></script>
    </body>
</html>

How to use a for loop to iterate through a table?, "indextable" is the table I am trying to loop through, and the values of However, when I try the code below, rather than getting the appropriate values ex. would give us the data for what is in the table and you could 'splain� Using a nested .each() means that your inner loop is doing one td at a time, so you can't set the productId and product and quantity all in the inner loop.. Also using function(key, val) and then val[key].innerHTML isn't right: the .each() method passes the index (an integer) and the actual element, so you'd use function(i, element) and then element.innerHTML.

The Basics of Python For Loops: A Tutorial, When you're working with data in Python, for loops can be a powerful in our table, since those are the column names and we will get an error� Add (Insert) rows in DataTable using For Each loop using C# and VB.Net. When the Copy Button is clicked, a new DataTable is created with columns same as that of the GridView. Then a loop is executed and one by one each GridView Row is copied / added / transferred to the DataTable.

How to go loop a data table like a for each but not using one?, My problem I need to resolve: Currently I have a for loop, looping through How do I make it so when it loops back into my for loop the for loop� Hi! I am very new to programming and I am trying to understand how to loop through a table. "indextable" is the table I am trying to loop through, and the values of indextable are the indices of cellnames. Hence I want 'i' to represent the values in indextable, rather than the indices.

In Excel VBA, the most common use of a For Loop is to read through a range. Imagine we have the data set in the screenshot below. Our task is to write code that will read through the data and copy the amounts to the column J. We are only going to copy amounts that are greater than 200,000.

Comments
  • you close the TR before adding your TDs...and don't close the TDs either
  • And to add to what @Ctznkane525 said, you put each of your headings in their own row, which is why they display each on their own row.