Making calculations in a HTML table

I have a created a HTML table which is editable.
The table contains some cells are predefined with the numbers 1-5, than there is section where the user can enter data and in the last column there should be the result of the data of the previous cells. Now I want the add a formula like you have for instances with Excel. How I can make calculations in the HTML table with Javascript or any other method?

Details table

enter image description here

Column 1: packages is predefined
Column 2: here user can add weight in kg
Column 3: user adds here the length
Column 4: user adds here the width
Column 5: user adds here height
Column 6: user adds split (%)
Column 7: Volume weight = result formule is:length x width x height x 200

HTML table + script

function calculateVolumeWeight() {
            let totalSplit = 0;
            const errorElement = document.getElementById('error');
            errorElement.innerHTML = ""; // Clear previous errors

            for (let i = 1; i <= 3; i++) {
                // Get input values
                const length = parseFloat(document.getElementById(`length${i}`).value) || 0;
                const width = parseFloat(document.getElementById(`width${i}`).value) || 0;
                const height = parseFloat(document.getElementById(`height${i}`).value) || 0;
                const split = parseFloat(document.getElementById(`split${i}`).value) || 0;

                // Calculate volume weight
                const volumeWeight = (length * width * height) / 200;

                // Display volume weight
                document.getElementById(`volumeWeight${i}`).innerText = volumeWeight.toFixed(2);

                // Accumulate split percentages
                totalSplit += split;
            }

            // Validate the total split
            if (totalSplit !== 100) {
                errorElement.innerHTML = "Error: The total split percentage must equal 100%.";
            } else {
                errorElement.innerHTML = "Total split is correct.";
            }
        }

        // Add event listeners to all input fields
        document.querySelectorAll('input').forEach(input => {
            input.addEventListener('input', calculateVolumeWeight);
});
table {
            width: 100%;
            border-collapse: collapse;
        }
        table, th, td {
            border: 1px solid black;
        }
        th, td {
            padding: 10px;
            text-align: center;
        }
        #error {
            color: red;
            margin-top: 20px;
        }
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Auto-Calculate Packaging Table</title>
  </head>
  <body>
    <h2>Top 3 Packaging in Use</h2>
    <table>
        <thead>
            <tr>
                <th>Packages</th>
                <th>Weight (kg)</th>
                <th>Length (cm)</th>
                <th>Width (cm)</th>
                <th>Height (cm)</th>
                <th>Split (%)</th>
                <th>*Volume Weight</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>1</td>
                <td><input type="number" id="weight1" step="any"></td>
                <td><input type="number" id="length1" step="any"></td>
                <td><input type="number" id="width1" step="any"></td>
                <td><input type="number" id="height1" step="any"></td>
                <td><input type="number" id="split1" step="any"></td>
                <td><span id="volumeWeight1">0</span></td>
            </tr>
            <tr>
                <td>2</td>
                <td><input type="number" id="weight2" step="any"></td>
                <td><input type="number" id="length2" step="any"></td>
                <td><input type="number" id="width2" step="any"></td>
                <td><input type="number" id="height2" step="any"></td>
                <td><input type="number" id="split2" step="any"></td>
                <td><span id="volumeWeight2">0</span></td>
            </tr>
            <tr>
                <td>3</td>
                <td><input type="number" id="weight3" step="any"></td>
                <td><input type="number" id="length3" step="any"></td>
                <td><input type="number" id="width3" step="any"></td>
                <td><input type="number" id="height3" step="any"></td>
                <td><input type="number" id="split3" step="any"></td>
                <td><span id="volumeWeight3">0</span></td>
            </tr>
        </tbody>
    </table>

    <p id="error"></p>
  </body>
</html>

What I tried
I did some research and many posts mention adding javascript to make calculations. I wrote the above code, the split percentage needs te be 100 % and all the fields needs to be filled. Which should results in a result in volume weight but nothing happends.

6

You could iterate over the table rows and tabulate like so

const recalculate = (ev) => {

   document.querySelectorAll('tbody > tr').forEach(row => {
   
      const cells = row.children;

      //  formule is:length x width x height x 200

      let length = Number(cells.item(2).innerText);
      let width = Number(cells.item(3).innerText);
      let height = Number(cells.item(4).innerText);

      row.lastElementChild.innerText = length * width * height * 200;
   });

};

document.querySelectorAll('[contenteditable="true"]').forEach(el => {
    el.addEventListener("input",recalculate);
});
table td {
    border: 1px dotted gray;
}
  <table>
    <caption>
      <p><strong>Volume weight = L X W X H * 200</strong></p>
    </caption>
    <thead>
      <tr>
        <th>Packages</th>
        <th>Weight (kg)</th>
        <th>
          <p>Length (cm)</p>
        </th>
        <th>Width (cm)</th>
        <th>Height (cm)</th>
        <th>Split (%)</th>
        <th>*Volume weight</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>1</td>
        <td contenteditable="true"> </td>
        <td contenteditable="true"> </td>
        <td contenteditable="true"> </td>
        <td contenteditable="true"> </td>
        <td contenteditable="true"> </td>
        <td> </td>
      </tr>
      <tr>
        <td>2</td>
        <td contenteditable="true"> </td>
        <td contenteditable="true"> </td>
        <td contenteditable="true"> </td>
        <td contenteditable="true"> </td>
        <td contenteditable="true"> </td>
        <td> </td>
      </tr>
      <tr>
        <td>3</td>
        <td contenteditable="true"> </td>
        <td contenteditable="true"> </td>
        <td contenteditable="true"> </td>
        <td contenteditable="true"> </td>
        <td contenteditable="true"> </td>
        <td> </td>
      </tr>
      <tr>
        <td>4</td>
        <td contenteditable="true"> </td>
        <td contenteditable="true"> </td>
        <td contenteditable="true"> </td>
        <td contenteditable="true"> </td>
        <td contenteditable="true"> </td>
        <td> </td>
      </tr>
      <tr>
        <td>5</td>
        <td contenteditable="true"> </td>
        <td contenteditable="true"> </td>
        <td contenteditable="true"> </td>
        <td contenteditable="true"> </td>
        <td contenteditable="true"> </td>
        <td> </td>
      </tr>
    </tbody>
  </table>

2

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