Uncaught TypeError: $(...).onChange is not a function

somutesting

i am developing area calculator with width height and uint when i enter width and height it has to multiply and when ever i change the the unit that particular result has to come. but when i enter width and height i am getting error like Uncaught TypeError: $(...).onChange is not a function How can i solve this one?

Below is my code

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <link
      rel="stylesheet"
      href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css"
    />
    <style>
      .tt-area-calculator-title {
        text-align: right;
        cursor: pointer;
        margin-bottom: 10px;
        font-weight: 600;
        font-size: 14px;
        color: #01acf1;
      }
      .tt-calculator-container {
        display: block;
        opacity: 0;
        visibility: hidden;
        height: 0;
      }
      .active {
        opacity: 1;
        visibility: visible;
        height: auto;
      }
      .areacalc {
        text-align: center;
        font-size: 14px;
        line-height: 16px;
        border: 1px solid #d7d7d7;
        background: #f8f8f8;
        color: #262626;
        margin-bottom: 20px;
      }
      .areacalc-column {
        float: none;
        width: 100%;
      }
      .areacalc-column-inner {
        padding: 0 0 5px;
      }
      .areacalc-label {
        color: #21293c;
        padding: 4px 0;
        font-weight: 600;
        text-transform: uppercase;
      }
      p {
        margin-top: 0;
        margin-bottom: 0.9rem;
      }
      .areacalc-table-measurements {
        text-align: center;
      }
      table {
        width: 100%;
        border-collapse: collapse;
        border-spacing: 0;
        max-width: 100%;
      }
      tbody {
        display: table-row-group;
        vertical-align: middle;
        border-color: inherit;
      }
      .areacalc-table-measurements {
        text-align: center;
      }
      tr {
        display: table-row;
        vertical-align: inherit;
        border-color: inherit;
      }
      .areacalc-table-measurements {
        text-align: center;
      }
      .areacalc-column th {
        padding: 2px;
        font-weight: 400;
        text-align: center;
      }
      .areacalc-column td {
        padding: 2px;
      }
      .table-l {
        text-align: right;
        width: 50%;
      }

      .table-r {
        text-align: left;
        width: 50%;
        font-weight: 700;
      }
      .areacalc-input,
      select.areacalc-select {
        padding: 0 5px !important;
        height: 26px !important;
        border: 1px solid #c2c2c2;
      }
      .cell-d {
        font-weight: 600;
        padding: 6px 0 !important;
      }
    </style>
  </head>
  <body>
    <div class="tt-area-calculator-title">
      <span class="tt-calculator-span"
        ><i class="fas fa-calculator"></i> Area Calculator</span
      >
    </div>
    <div
      id="tt-area-calculator-container"
      class="tt-calculator-container"
      data-bind="scope: 'area_calculator'"
    >
      <!-- ko template: getTemplate() -->
      <div class="areacalc">
        <!-- COLUMN 1 -->
        <div class="areacalc-column">
          <!-- AREA TO BE TILED -->
          <div class="areacalc-column-inner">
            <p class="areacalc-label" data-bind="i18n: 'Area(s) to be tiled'">
              Area(s) to be tiled
            </p>
            <table class="areacalc-table-measurements" style="width: 100%">
              <tbody>
                <tr>
                  <th style="width: 12%"></th>
                  <th style="width: 22%" data-bind="i18n: 'Width'">Width</th>
                  <th style="width: 22%" data-bind="i18n: 'Height'">Height</th>
                  <th style="width: 22%" data-bind="i18n: 'Unit'">Unit</th>
                  <th style="width: 22%" data-bind="i18n: 'Area'">Area</th>
                </tr>
                <!-- ko foreach: {data: $data.areaTiled, as: '$row' } -->
                <tr data-bind="css: {'_last': $row.isLast()}" class="_last">
                  <td class="cell-a">
                    <!-- ko if: $row.canDelete --><!-- /ko -->
                  </td>
                  <td class="cell-b">
                    <input
                      id="areaWidth"
                      class="areacalc-input"
                      type="text"
                      name="width"
                      data-bind="value: $row.width, valueUpdate: 'keyup'"
                    />
                  </td>
                  <td class="cell-c">
                    <input
                      id="areaHeight"
                      class="areacalc-input"
                      type="text"
                      name="height"
                      data-bind="value: $row.height, valueUpdate: 'keyup'"
                    />
                  </td>
                  <td class="cell-u">
                    <select
                      name="unit"
                      class="areacalc-select"
                      data-bind="options: $parent.unitsArray, value: selectedUnit"
                    >
                      <option value="m">m</option>
                      <option value="mm">mm</option>
                      <option value="cm">cm</option>
                      <option value="inches">inches</option>
                      <option value="feet">feet</option>
                    </select>
                  </td>
                  <td class="cell-d">
                    <span id="total" data-bind="text: $row.square">0</span>
                    <span>m²</span>
                  </td>
                </tr>
                <!-- /ko -->
                <tr>
                  <td></td>
                  <td></td>
                  <td></td>
                  <td></td>
                  <td style="font-weight: 600; padding: 6px 0px !important">
                    <span data-bind="i18n: 'Total'">Total</span>
                    <span id="totalvalue" data-bind="text: $data.areaTiledTotal"
                      >0</span
                    >
                    <span>m²</span>
                  </td>
                </tr>
              </tbody>
            </table>

            <!-- AREA TO BE DEDUCTED -->
            <p
              class="areacalc-label"
              data-bind="i18n: 'Area(s) to be deducted'"
            >
              Area(s) to be deducted
            </p>
            <table class="areacalc-table-measurements" style="width: 100%">
              <tbody>
                <tr>
                  <th style="width: 12%"></th>
                  <th style="width: 22%" data-bind="i18n: 'Width'">Width</th>
                  <th style="width: 22%" data-bind="i18n: 'Height'">Height</th>
                  <th style="width: 22%" data-bind="i18n: 'Unit'">Unit</th>
                  <th style="width: 22%" data-bind="i18n: 'Area'">Area</th>
                </tr>
                <!-- ko foreach: {data: $data.areaDeducted, as: '$row' } -->
                <tr data-bind="css: {'_last': $row.isLast()}" class="_last">
                  <td class="cell-a">
                    <!-- ko if: $row.canDelete --><!-- /ko -->
                  </td>
                  <td class="cell-b">
                    <input
                      id="areaWidth1"
                      class="areacalc-input"
                      type="text"
                      name="width"
                      data-bind="value: $row.width, valueUpdate: 'keyup'"
                    />
                  </td>
                  <td class="cell-c">
                    <input
                      id="areaHeight1"
                      class="areacalc-input"
                      type="text"
                      name="height"
                      data-bind="value: $row.height, valueUpdate: 'keyup'"
                    />
                  </td>
                  <td class="cell-u">
                    <select
                      name="unit"
                      class="areacalc-select"
                      data-bind="options: $parent.unitsArray, value: selectedUnit"
                    >
                      <option value="m">m</option>
                      <option value="mm">mm</option>
                      <option value="cm">cm</option>
                      <option value="inches">inches</option>
                      <option value="feet">feet</option>
                    </select>
                  </td>
                  <td class="cell-d">
                    <span id="total1" data-bind="text: $row.square">0</span>
                    <span>m²</span>
                  </td>
                </tr>
                <!-- /ko -->
                <tr>
                  <td></td>
                  <td></td>
                  <td></td>
                  <td></td>
                  <td style="font-weight: 600; padding: 6px 0px !important">
                    <span data-bind="i18n: 'Total'">Total</span>
                    <span
                      id="totalvalue1"
                      data-bind="text: $data.areaDeductedTotal"
                      >0</span
                    >
                    <span>m²</span>
                  </td>
                </tr>
              </tbody>
            </table>
          </div>
        </div>

        <!-- COLUMN 2 -->
        <div class="areacalc-column">
          <div class="areacalc-column-inner">
            <p class="areacalc-label">You will need</p>
            <table class="areacalc-table-results" style="width: 100%">
              <tbody>
                <tr>
                  <td class="table-l">Total area:</td>
                  <td class="table-r">
                    <span data-bind="text: $data.areaTotal">0</span>
                    <span>m²</span>
                  </td>
                </tr>
                <tr>
                  <td class="table-l">Tiles required:</td>
                  <td class="table-r" data-bind="text: $data.tilesRequired">
                    0
                  </td>
                </tr>
                <tr>
                  <td class="table-l"></td>
                  <td class="table-r"></td>
                </tr>
                <tr>
                  <td class="table-l">Est. Grout required:</td>
                  <td class="table-r">
                    <span data-bind="text: $data.groutBags">0</span>
                    <span data-bind="i18n: 'x 3kg bag(s)'">x 3kg bag(s)</span>
                  </td>
                </tr>
                <tr>
                  <td class="table-l">Est. Adhesive required:</td>
                  <td class="table-r">
                    <span data-bind="text: $data.adhesiveBags">0</span>
                    <span data-bind="i18n: 'bag(s)'">bag(s)</span>
                  </td>
                </tr>
                <tr>
                  <td class="table-l">
                    <span data-bind="i18n: 'Add'">Add</span>
                    <span data-bind="text: $data.waste + '%'">10%</span>
                    <span data-bind="i18n: 'for wastage?'">for wastage?</span>
                  </td>
                  <td class="table-r">
                    <input
                      type="checkbox"
                      style="float: left; margin-right: 5px"
                      data-bind="checked: $data.isWasteEnabled"
                    />
                  </td>
                </tr>
              </tbody>
            </table>
          </div>
        </div>
      </div>
      <!-- /ko -->
    </div>
    <script
      src="https://code.jquery.com/jquery-3.6.0.slim.min.js"
      integrity="sha256-u7e5khyithlIdTpu22PHhENmPcRdFiHRjhAuHcs05RI="
      crossorigin="anonymous"
    ></script>
    <script>
      $(document).ready(function () {
        $(".tt-area-calculator-title").click(function () {
          $(".tt-calculator-container").toggleClass("active");
        });
      });
      $("#areaWidth,#areaHeight").keyup(function () {
        var textValue1 = $("#areaWidth").val();
        var textValue2 = $("#areaHeight").val();
        var total = textValue1 * textValue2;
        var measurement = document.querySelector(".areacalc-select").value;
        console.log(measurement);
        $(document).ready(function () {
          $(".areacalc-select").onChange(function () {
            if (measurement === "m") {
              return total;
              document.getElementById("total").innerHTML = total;
              document.getElementById("totalvalue").innerHTML = total;
            } else if (measurement === "mm") {
              document.getElementById("total").innerHTML = total * 3;
              document.getElementById("totalvalue").innerHTML = total * 3;
            } else if (measurement === "cm") {
              document.getElementById("total").innerHTML = total * 4;
              document.getElementById("totalvalue").innerHTML = total * 4;
            } else if (measurement === "inches") {
              document.getElementById("total").innerHTML = total * 5;
              document.getElementById("totalvalue").innerHTML = total * 5;
            } else {
              document.getElementById("total").innerHTML = total * 6;
              document.getElementById("totalvalue").innerHTML = total * 6;
            }
          });
        });
      });
      $("#areaWidth1,#areaHeight1").keyup(function () {
        var textValue1 = $("#areaWidth1").val();
        var textValue2 = $("#areaHeight1").val();
        var total = textValue1 * textValue2;
        document.getElementById("total1").innerHTML = total;
        document.getElementById("totalvalue1").innerHTML = total;
      });
    </script>
  </body>
</html>

For reference please find the attached image also. enter image description here

Sang Suantak

The correct syntax should be $(".areacalc-select").on("change", function () {

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Uncaught TypeError: setUserName is not a function at onChange

Ngx-tinymce Uncaught TypeError: _this.onChange is not a function

Uncaught TypeError: Function is not a function

TypeError: setEmail is not a function onChange

very simple script fails on onChange event. Uncaught TypeError: document.getElementbyId is not a function

Uncaught TypeError: $(...).jsGrid is not a function

Uncaught TypeError: $(…).on is not a function

Uncaught TypeError: $(...).accordion is not a function

Uncaught TypeError: $(...).formSelect is not a function

Uncaught TypeError: $(...).stellar is not a function

Uncaught TypeError: $(...).tooltip is not a function

Uncaught TypeError: $(...).pickadate is not a function

Uncaught TypeError: $(...).ready is not a function

Uncaught TypeError: 'download' is not a function

Uncaught TypeError: $(...).tableDnD is not a function

Javascript: Uncaught TypeError: not a function

Uncaught TypeError: #<Object> is not a function

Uncaught TypeError: $.post is not a function

Uncaught TypeError: map is not a function

Uncaught TypeError: Object (...) is not a function

Uncaught TypeError Object is not a function

Uncaught TypeError: .slideToggle is not a function

Uncaught TypeError: $(...).waterwheelCarousel is not a function

"Uncaught TypeError: $ is not a function" in WordPress

Uncaught TypeError: .unshift is not a function

Uncaught TypeError: dispatch(...).then is not a function

Uncaught TypeError: $(...).selectize is not a function

Uncaught TypeError: $ is not a function on weebly

Uncaught TypeError: getFullYear is not a function