Table Multiple Row Sum, Subtraction,Multiplication,Division - fabulouscode

Sunday, November 22, 2020

Table Multiple Row Sum, Subtraction,Multiplication,Division

Table Multiple Row Sum, Subtraction,Multiplication,Division  



<!DOCTYPE html>

<html>

<head>

<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>

  <meta charset="utf-8">

  <title>Example</title>

</head>

<body>

  <table>

    <thead>

      <tr>

        <th>Quantity</th>

        <th>Price</th>

        <th>Total</th>

      </tr>

    </thead>

    <tbody>

      <tr>

        <td><input type="text" class="qty"></td>

        <td><input type="text" class="price"></td>

        <td><input type="text" class="total" disabled></td>

      </tr>

      <!-- ...and so on... -->

    </tbody>

  </table>

<script>

  (function() {

    "use strict";


    $("table").on("change", "input", function() {

      var row = $(this).closest("tr");

      var qty = parseFloat(row.find(".qty").val());

      var price = parseFloat(row.find(".price").val());

      var total = qty * price;

      row.find(".total").val(isNaN(total) ? "" : total);

    });

  })();

</script>

</body>

</html>

No comments:

Post a Comment

I am Safiqul Islam Tuhin