Comment soustraire le montant total et le montant payé et afficher la réponse dans une autre zone de texte

la programmation

[ad_1]

XML
<script src="jquery-1.3.2.min.js" type="text/javascript"></script>
  <script type="text/javascript">
      $(document).ready(function () {
                   $("#AmountId").change(function () {
              var a = parseInt($('#TotaltobePaid').val(), 10);
              var b = parseInt($('#AmountId').val(), 10);
              $('form').submit();
              var result=0;
              a = isNaN(a) ? 0 : a;
              b = isNan(b) ? 0 : b;
              if (a > 0 && b > 0)
                  result = a - b;
              $("#Balance").text(+result);

          });

      });

voici mon code html

HTML
@Html.LabelFor(model => model.TotaltobePaid)
 

@Html.EditorFor(model => model.TotaltobePaid, new { name = "Totaltobepaid", id = "TotaltobePaid" })
 
 

@Html.LabelFor(model => model.AmountPaid)
 

@Html.EditorFor(model => model.AmountPaid, new { name = "Amount", id = "AmountId" })
<button class="btn btn-primary" id="AmountButton">Go</button>
 

@Html.LabelFor(model => model.Balance)
 

@Html.EditorFor(model => model.Balance, new { name = "Balance", id = "Balance" })

Ce que j’ai essayé :

<pre lang="HTML">@Html.LabelFor(model => model.TotaltobePaid)
 

@Html.EditorFor(model => model.TotaltobePaid, new { name = "Totaltobepaid", id = "TotaltobePaid" })
 
 

@Html.LabelFor(model => model.AmountPaid)
 

@Html.EditorFor(model => model.AmountPaid, new { name = "Amount", id = "AmountId" })
<button class="btn btn-primary" id="AmountButton">Go</button>
 

@Html.LabelFor(model => model.Balance)
 

@Html.EditorFor(model => model.Balance, new { name = "Balance", id = "Balance" })

Solution 1

Javascript
<script type="text/javascript">
      $(document).ready(function () {
                   $("#AmountId").change(function () {
              var a = parseInt($('#TotaltobePaid').val(), 10);
              var b = parseInt($('#AmountId').val(), 10);
              $('form').submit();
              var result=0;
              a = isNaN(a) ? 0 : a;
              b = isNan(b) ? 0: b;
              if (a > 0 && b > 0)
                  result = a - b;
              $("#Balance").text(+result); 
          }); 
      });
</script>

b = estNan(b) ? 0 : b ;
vérifie la ligne

b = estNaN
(b) ? 0 : b ;

[ad_2]

コメント

Titre et URL copiés