Create html table from array with calc function?

Im trying to create a html page with a table that will show a list of different “objects”. These objects all have a calculated value in a measuring point, a total sum are calculated at the end (noise level). The calculated value should be recalculated to see what difference it makes to the whole value.

Ive made a version that works for the 3 objects added to test the javascript. But since I have about 300 objects its not time efficient to manually add all the objects by hand.

So, have do I create a table for about 300 objects the simplest way?

<!DOCTYPE html>
<html>
<head>
    <title>Table</title>
    <style>
        table {
            width: 100%;
            border-collapse: collapse;
        }
        th, td {
            border: 1px solid black;
            padding: 15px;
            text-align: left;
        }
    </style>
</head>
<body>
    <table>
        <tr>
            <th>Bullerkälla</th>
            <th>LW</th>
            <th>MP1</th>
            <th>MP2</th>
            <th>MP3</th>
            <th>Input</th>
            <th>Sum MP1</th>
        <th>Sum MP2</th>
        <th>Sum MP3</th>
            <th style="display:none;">Recalculated Sum MP1</th>
            <th style="display:none;">Recalculated Sum MP2</th>
            <th style="display:none;">Recalculated Sum MP3</th>
        </tr>
        <tr>
            <td>101. Ventilationshus (Nordost)</td>
            <td id="lw1">86</td>
            <td id="mp1_1">19,1</td>
            <td id="mp2_1">-11</td>
            <td id="mp3_1">-11</td>
            <td><input type="number" id="input1" oninput="calculateSum(1)"></td>
            <td id="MP1sum1"></td>
            <td id="MP2sum1"></td>
            <td id="MP3sum1"></td>
            <td id="MP1recalc1" style="display:none;"></td>
            <td id="MP2recalc1" style="display:none;"></td>
            <td id="MP3recalc1" style="display:none;"></td>
        </tr>
        <tr>
            <td>101. Ventilationshus (Sydväst)</td>
            <td id="lw2">86</td>
            <td id="mp1_2">-4,2</td>
            <td id="mp2_2">-5</td>
            <td id="mp3_2">-5</td>
            <td><input type="number" id="input2" oninput="calculateSum(2)"></td>
            <td id="MP1sum2"></td>
            <td id="MP2sum2"></td>
            <td id="MP3sum2"></td>
            <td id="MP1recalc2" style="display:none;"></td>
            <td id="MP2recalc2" style="display:none;"></td>
            <td id="MP3recalc2" style="display:none;"></td>
        </tr>
        <tr>
            <td>102. Ventilationshus (Nordväst)</td>
            <td id="lw3">89</td>
            <td id="mp1_3">21,5</td>
            <td id="mp2_3">-6</td>
            <td id="mp3_3">-6</td>
            <td><input type="number" id="input3" oninput="calculateSum(3)"></td>
            <td id="MP1sum3"></td>
            <td id="MP2sum3"></td>
            <td id="MP3sum3"></td>
            <td id="MP1recalc3" style="display:none;"></td>
            <td id="MP2recalc3" style="display:none;"></td>
            <td id="MP3recalc3" style="display:none;"></td>
        </tr>
        <tr>
            <td colspan="6">Total</td>
            <td id="MP1total"></td>
            <td id="MP2total"></td>
            <td id="MP3total"></td>
            <td colspan="2" style="display:none;"></td>
        </tr>
    </table>


<script> 

window.onload = function() {
    // Assuming the input elements have ids 'input1', 'input2', etc.
    var i = 1;
    while(document.getElementById('input' + i)) {
        document.getElementById('input' + i).value = 0;
      let mp1 = parseFloat(document.getElementById("mp1_" + i).innerText);
      let mp2 = parseFloat(document.getElementById("mp2_" + i).innerText);
      let mp3 = parseFloat(document.getElementById("mp3_" + i).innerText);
          document.getElementById("MP1sum" + i).innerText = mp1;
          document.getElementById("MP2sum" + i).innerText = mp2;
          document.getElementById("MP3sum" + i).innerText = mp3;
          document.getElementById("MP1recalc" + i).innerText = Math.pow(10, mp1 / 10);
          document.getElementById("MP2recalc" + i).innerText = Math.pow(10, mp2 / 10);
          document.getElementById("MP3recalc" + i).innerText = Math.pow(10, mp3 / 10);
        i++;
    }
          calculateTotal();

};

element.dispatchEvent(event);

      function calculateSum(row) {
      let mp1 = parseFloat(document.getElementById("mp1_" + row).innerText);
      let mp2 = parseFloat(document.getElementById("mp2_" + row).innerText);
      let mp3 = parseFloat(document.getElementById("mp2_" + row).innerText);
      let input = parseFloat(document.getElementById("input" + row).value);
      let MP1sum = mp1 - input;
          let MP2sum = mp2 - input;
          let MP3sum = mp3 - input;
          document.getElementById("MP1sum" + row).innerText = MP1sum;
          document.getElementById("MP2sum" + row).innerText = MP2sum;
          document.getElementById("MP3sum" + row).innerText = MP3sum;
          document.getElementById("MP1recalc" + row).innerText = Math.pow(10, MP1sum / 10);
          document.getElementById("MP2recalc" + row).innerText = Math.pow(10, MP2sum / 10);
          document.getElementById("MP3recalc" + row).innerText = Math.pow(10, MP3sum / 10);
          calculateTotal();
      }
        function calculateTotal() {
            var totalMP1 = 0;
            var totalMP2 = 0;
            var totalMP3 = 0;
            for (var i = 1; i <= 3; i++) {
                totalMP1 += parseFloat(document.getElementById("MP1recalc" + i).innerText);
                totalMP2 += parseFloat(document.getElementById("MP2recalc" + i).innerText);
                totalMP3 += parseFloat(document.getElementById("MP3recalc" + i).innerText);
            }
        var LogTotalMP1 = 10*Math.log10(totalMP1);
        var LogTotalMP2 = 10*Math.log10(totalMP2);
        var LogTotalMP3 = 10*Math.log10(totalMP3);
            document.getElementById("MP1total").innerText = Math.round(LogTotalMP1*10)/10;
            document.getElementById("MP2total").innerText = Math.round(LogTotalMP2*10)/10;
            document.getElementById("MP3total").innerText = Math.round(LogTotalMP3*10)/10;
        }
    </script>
</body>
</html>

New contributor

Mikael Hörnqvist is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật