2021年1月18日星期一

jQuery Won't Compute Fields

everybody i have a jquery form that must calculate the values and go to backend to process (nothig new), but just calculate the first two, others doesnt. any suggestion?

JS    $("#mainContainerTab").on("change", '#balDecPreYeabNiifAnnexPorRes, #balDecPreYeaTaxAnnexPorRes', function () {    let val1 = parseInt($('#balDecPreYeabNiifAnnexPorRes').val());    let val2 = parseInt($('#balDecPreYeaTaxAnnexPorRes').val());    if (!val1) val1 = 0;    if (!val2) val2 = 0;    $('#balDecPreYeaTotAnnexPorRes').val(val1 + val2)  });    $("#mainContainerTab").on("change", '#curYeaProExpbNiifAnnexPorRes, #curYeaProExpTaxAnnexPorRes', function () {    let val1 = parseInt($('#curYeaProExpbNiifAnnexPorRes').val());    let val2 = parseInt($('#curYeaProExpTaxAnnexPorRes').val());    if (!val1) val1 = 0;    if (!val2) val2 = 0;    $('#curYeaProExpTotAnnexPorRes').val(val1 + val2)  });    $("#mainContainerTab").on("change", '#revRecCurYeabNiifAnnexPorRes, #revRecCurYeaTaxAnnexPorRes', function () {    let val1 = parseInt($('#revRecCurYeabNiifAnnexPorRes').val());    let val2 = parseInt($('#revRecCurYeaTaxAnnexPorRes').val());    if (!val1) val1 = 0;    if (!val2) val2 = 0;    $('#revRecCurYeaTotAnnexPorRes').val(val1 + val2)  });    $("#mainContainerTab").on("change", '#canCurYeabNiifAnnexPorRes, #canCurYeaTaxAnnexPorRes', function () {    let val1 = parseInt($('#canCurYeabNiifAnnexPorRes').val());    let val2 = parseInt($('#canCurYeaTaxAnnexPorRes').val());    if (!val1) val1 = 0;    if (!val2) val2 = 0;    $('#canCurYeaTotAnnexPorRes').val(val1 + val2)  });    $("#mainContainerTab").on("change", '#recOfOthConbNiifAnnexPorRes, #recOfOthConTaxAnnexPorRes', function () {    let val1 = parseInt($('#recOfOthConbNiifAnnexPorRes').val());    let val2 = parseInt($('#recOfOthConTaxAnnexPorRes').val());    if (!val1) val1 = 0;    if (!val2) val2 = 0;    $('#recOfOthConTotAnnexPorRes').val(val1 + val2)  });    

and here is the HTML is a simple table inside a form to send to back

HTML     <table class="mt table table-hover table-bordered table-striped" style="width: 96%; margin-left: 2%;">    <tbody>      <thead>        <tr>          <th style ="width: 150px">Movimiento reserva general o individual de cartera</th>          <th style ="width: 150px">Balance NIIF</th>          <th style ="width: 150px">Fiscal</th>          <th style ="width: 150px">Sin aceptacion</th>        </tr>      </thead>      <tr>        <th>Saldo diciembre año anterior</th>        <th>          <div class="col-sm-10">            <input               type="number"               class="form-control change-num"               id="balDecPreYeabNiifAnnexPorRes"              placeholder="Saldo diciembre año anterior"              data-validate="lleno:Indique Saldo diciembre año anterior"               step=0.01 />            <div class="invalid-feedback"></div>          </div>        </th>        <th>          <div class="col-sm-10">            <input               type="number"               class="form-control change-num"               id="balDecPreYeaTaxAnnexPorRes"              placeholder="Saldo diciembre año anterior"              data-validate="lleno:Indique Saldo diciembre año anterior"               step=0.01 />            <div class="invalid-feedback"></div>          </div>        </th>        <th>          <div class="col-sm-10">            <input               type="number"               class="form-control change"               id="balDecPreYeaTotAnnexPorRes"              placeholder="Saldo diciembre año anterior"              disabled />            <div class="invalid-feedback"></div>          </div>        </th>      </tr>      <tr>        <th>Gasto provision año actual</th>        <th>          <div class="col-sm-10">            <input               type="number"               class="form-control change-num"               id="curYeaProExpbNiifAnnexPorRes"              placeholder="Gasto provision año actual"              data-validate="lleno:Indique Gasto provision año actual"               step=0.01 />            <div class="invalid-feedback"></div>          </div>        </th>        <th>          <div class="col-sm-10">            <input               type="number"               class="form-control change-num"               id="curYeaProExpTaxAnnexPorRes"              placeholder="Gasto provision año actual"              data-validate="lleno:Indique Gasto provision año actual"               step=0.01 />            <div class="invalid-feedback"></div>          </div>        </th>        <th>          <div class="col-sm-10">            <input               type="number"               class="form-control change"               id="curYeaProExpTotAnnexPorRes"              placeholder="Gasto provision año actual"              disabled />            <div class="invalid-feedback"></div>          </div>        </th>      </tr>      <tr>        <th>Revisiones/recuperacion año actual</th>        <th>          <div class="col-sm-10">            <input               type="number"               class="form-control change-num"               id="revRecCurYeabNiifAnnexPorRes"              placeholder="Revisiones/recuperacion año actual"              data-validate="lleno:Indique Revisiones/recuperacion año actual"               step=0.01 />            <div class="invalid-feedback"></div>          </div>        </th>        <th>          <div class="col-sm-10">            <input               type="number"               class="form-control change-num"               id="revRecCurYeaTaxAnnexPorRes"              placeholder="Revisiones/recuperacion año actual"              data-validate="lleno:Indique Revisiones/recuperacion año actual"               step=0.01 />            <div class="invalid-feedback"></div>          </div>        </th>        <th>          <div class="col-sm-10">            <input               type="number"               class="form-control change"               id="revRecCurYeaTotAnnexPorRes"              placeholder="Revisiones/recuperacion año actual"              disabled />            <div class="invalid-feedback"></div>          </div>        </th>      </tr>      <tr>        <th>Reclasificaciones otros conceptos</th>        <th>          <div class="col-sm-10">            <input               type="number"               class="form-control change-num"               id="canCurYeabNiifAnnexPorRes"              placeholder="Reclasificaciones otros conceptos"              data-validate="lleno:Indique Reclasificaciones otros conceptos"               step=0.01 />            <div class="invalid-feedback"></div>          </div>        </th>        <th>          <div class="col-sm-10">            <input               type="number"               class="form-control change-num"               id="canCurYeaTaxAnnexPorRes"              placeholder="Reclasificaciones otros conceptos"              data-validate="lleno:Indique Reclasificaciones otros conceptos"               step=0.01 />            <div class="invalid-feedback"></div>          </div>        </th>        <th>          <div class="col-sm-10">            <input               type="number"               class="form-control change"               id="canCurYeaTotAnnexPorRes"              placeholder="Reclasificaciones otros conceptos"              disabled />            <div class="invalid-feedback"></div>          </div>        </th>      </tr>      <tr>        <th>Saldo a diciembre 31 año actual</th>        <th>          <div class="col-sm-10">            <input               type="number"               class="form-control change-num"               id="recOfOthConbNiifAnnexPorRes"              placeholder="Saldo a diciembre 31 año actual"              data-validate="lleno:Indique Saldo a diciembre 31 año actual"               step=0.01 />            <div class="invalid-feedback"></div>          </div>        </th>        <th>          <div class="col-sm-10">            <input               type="number"               class="form-control change-num"               id="recOfOthConTaxAnnexPorRes"              placeholder="Saldo a diciembre 31 año actual"              data-validate="lleno:Indique Saldo a diciembre 31 año actual"               step=0.01 />            <div class="invalid-feedback"></div>          </div>        </th>        <th>          <div class="col-sm-10">            <input               type="number"               class="form-control change"               id="recOfOthConTotAnnexPorRes"              placeholder="Saldo a diciembre año actual"              disabled />            <div class="invalid-feedback"></div>          </div>        </th>      </tr>    </tbody>  </table>  

everything looks fine ( i guess), but when the fileds is filled, nothig happens in the last three fields i make a mistake? ( in other post i saw that change is when the user interact with the page and in this case is same, i try it with triggers but is the same). THNKS FOR UR HELP

https://stackoverflow.com/questions/65784092/jquery-wont-compute-fields January 19, 2021 at 08:52AM

没有评论:

发表评论