कुल राशि और भुगतान की गई राशि को कैसे घटाएं और उत्तर को दूसरे टेक्स्टबॉक्स में कैसे प्रदर्शित करें

[ad_1]

एक्सएमएल
<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);

          });

      });

यह मेरा 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" })

मैंने क्या प्रयास किया है:

<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" })

समाधान 1

जावास्क्रिप्ट
<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 = isNan(b) ? 0: बी;
लाइन की जाँच करें

बी = isNaN
(बी) ? 0: बी;

समाधान 2

जावास्क्रिप्ट
function subtraction() {
    var one = document.getElementById("one").value;
    var two = document.getElementById("two").value;
    var total = parseFloat(one) - parseFloat(two);
    document.getElementById("total").value = total;
}

[ad_2]

コメント

タイトルとURLをコピーしました