Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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);

          });

      });

heres my html code


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


What I have tried:

<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" })
Posted
Updated 22-Dec-23 3:30am
v2
Comments
ZurdoDev 19-Jul-13 12:01pm    
Just put a breakpoint in your code and see what is isn't doing what you want.
FirdousNasreen 19-Jul-13 14:14pm    
ok..sir.

1 solution

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 = isNan(b) ? 0: b;
check the line

b = isNaN
(b) ? 0: b;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900