Nikhil Dange
asked on
How to show difference using JavaScript
Why NaN?
I want to show difference between 'Total' and 'Paid' amount is 'Total Due' in JavaScript. How to show?
When I calculate 'Subtotal' and 'Tax' the ans will show in 'Total' cell and, When I'm trying to show 'Total Due' from (Total-Paid) then print NaN in 'Total Due' cell in JavaScript
How to do?
JavaScript :
function taxcal()
{
var per=100;
var subtotal=parseInt(document .getElemen tById('sub total').va lue);
var tax=parseInt(document.getE lementById ('tax').va lue);
var total=parseInt(document.ge tElementBy Id('total' ).value);
if (isNaN(tax)) tax=0;
var total1=(subtotal*(tax/per) .toFixed(2 ));
total=total1+subtotal;
document.getElementById("t otal").inn erHTML=tot al;
console.log(document.getEl ementById( 'total').v alue);
}
function totaldue()
{
var total=parseInt(document.ge tElementBy Id('total' ).value);
var paid=parseInt(document.get ElementByI d('paid'). value);
var totaldue=parseInt(document .getElemen tById('tot aldue').va lue);
var totaldue1=Math.abs((total- paid).toFi xed(2));
document.getElementById("t otaldue"). innerHTML= totaldue1;
}
HTML :
<table>
.
.
.
<td valign="middle" align="center" width="100%">
<input type="text" id="subtotal" name="subtotal" onKeyUp="result(this.form) " onKeyUp="taxcal(this.form) " class="subtotal" value="0.00" style="border:none;width: 100%;"/>
<input type="text" id="tax" class="tax" name="tax" onKeyUp="taxcal(this.form) " onKeyUp="totaldue(this.for m)" style="border:none;width: 100%;">
</td>
</tr>
</table>
</div>
<br>
<div class="form-group text-center">
<table style="float: left;margin-left: 25px;" cellpadding="1" cellspacing="1" border="1">
<tr><td width="70%" bgcolor="#e2dad8"><label style="font-style: bold;"><b><font size="4px">Comment :</b></label></td></tr>
<tr>
<td><textarea rows="2" style="width: 100%;border:none;" class="form-control"></tex tarea></td ></tr>
</table>
<table style="float: right;margin-right: 31px;" cellpadding="1" cellspacing="1" border="1" width="30%">
<tr>
<td width="20%" bgcolor="#e2dad8"><b><font size="4px">
Total</b>
</td>
<td width="10%">
<p name="total" id="total" onKeyUp="totaldue(this.for m)" readonly="readonly" value="00.00" class="text-center" style="border: none;"></p>
</td>
</tr>
<tr>
<td width="20%" bgcolor="#e2dad8"><b><font size="4px">Paid</b></td>
<td width="10%">
<input type="text" name="paid" onKeyUp="totaldue(this.for m)" id="paid" class="text-center" style="border:none;">
</td>
</tr>
<tr>
<td width="20%" bgcolor="#e2dad8"><b><font size="4px">Total Due</b></td>
<td width="10%">
<p class="text-center" id="totaldue" name="totaldue" value="0.00" onKeyUp="totaldue(this.for m)" readonly="readonly" style="border:none;"></p>
</td>
</tr>
</table>
</div>
I want to show difference between 'Total' and 'Paid' amount is 'Total Due' in JavaScript. How to show?
When I calculate 'Subtotal' and 'Tax' the ans will show in 'Total' cell and, When I'm trying to show 'Total Due' from (Total-Paid) then print NaN in 'Total Due' cell in JavaScript
How to do?
JavaScript :
function taxcal()
{
var per=100;
var subtotal=parseInt(document
var tax=parseInt(document.getE
var total=parseInt(document.ge
if (isNaN(tax)) tax=0;
var total1=(subtotal*(tax/per)
total=total1+subtotal;
document.getElementById("t
console.log(document.getEl
}
function totaldue()
{
var total=parseInt(document.ge
var paid=parseInt(document.get
var totaldue=parseInt(document
var totaldue1=Math.abs((total-
document.getElementById("t
}
HTML :
<table>
.
.
.
<td valign="middle" align="center" width="100%">
<input type="text" id="subtotal" name="subtotal" onKeyUp="result(this.form)
<input type="text" id="tax" class="tax" name="tax" onKeyUp="taxcal(this.form)
</td>
</tr>
</table>
</div>
<br>
<div class="form-group text-center">
<table style="float: left;margin-left: 25px;" cellpadding="1" cellspacing="1" border="1">
<tr><td width="70%" bgcolor="#e2dad8"><label style="font-style: bold;"><b><font size="4px">Comment :</b></label></td></tr>
<tr>
<td><textarea rows="2" style="width: 100%;border:none;" class="form-control"></tex
</table>
<table style="float: right;margin-right: 31px;" cellpadding="1" cellspacing="1" border="1" width="30%">
<tr>
<td width="20%" bgcolor="#e2dad8"><b><font
Total</b>
</td>
<td width="10%">
<p name="total" id="total" onKeyUp="totaldue(this.for
</td>
</tr>
<tr>
<td width="20%" bgcolor="#e2dad8"><b><font
<td width="10%">
<input type="text" name="paid" onKeyUp="totaldue(this.for
</td>
</tr>
<tr>
<td width="20%" bgcolor="#e2dad8"><b><font
<td width="10%">
<p class="text-center" id="totaldue" name="totaldue" value="0.00" onKeyUp="totaldue(this.for
</td>
</tr>
</table>
</div>
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Ya sure I'll try, and really thank you
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Thank You
Cause then you will see that the problem is how you try to read the data.
Open in new window
p.s. use the CODE button to embed code. It's much more reader friendly.