<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;