Hey guys im doing a POS for my body's store and im really bitting my nails on the form total calculations.
this is a test script
but it only calculates the grand total not the form part
they both work individual but when i add one it stops the filed calculator
this is a test script
but it only calculates the grand total not the form part
Code:
<script type="text/javascript">
///////////this is for filed total
function calc(A,B,SUM) {
var one = Number(A);
if (isNaN(one)) { alert('Invalid entry: '+A); one=0; }
var two = Number(document.getElementById(B).value);
if (isNaN(two)) { alert('Invalid entry: '+B); two=0; }
document.getElementById(SUM).value = one + two;
}
/////////////this is for grand total
function calcTotal(txtBox, totBox)
{
var totVal;
try
{
totVal = document.getElementById(totBox).value;
if(totVal!= null && totVal!='')
{
document.getElementById(totBox).value= eval(parseInt(document.getElementById(totBox).value) + parseInt(txtBox.value));
}
else
{
document.getElementById(totBox).value= txtBox.value;
}
}
catch(e)
{}
}
Code:
<table> <tr> <td width="337"><input name="sum1" id="op1" value="" onChange="calc(this.value,'op2','result')" /> <input name="sum2" value="" id="op2" onChange="calc(this.value,'op1','result')" /></td> <td width="176"><input type="text" id="result" onBlur="calcTotal(this, 'tot')" /></td> </tr> <tr> <td><input name="op" id="op3" value="" onchange="calc(this.value,'op4','result2')" /><input name="op" value="" id="op4" onchange="calc(this.value,'op3','result2')" /></td> <td><input type="text" id="result2" onBlur="calcTotal(this, 'tot')" /></td> </tr> <tr> <td> <input name="op" id="op5" value="" onchange="calc(this.value,'op5','result3')" /><input name="op" value="" id="op6" onchange="calc(this.value,'op6','result3')" /></td> <td><input type="text" id="result3" onBlur="calcTotal(this, 'tot')" /></td> </tr> <tr> <td>Total</td> <td><input type="text" id="tot" /></td> </tr> </table>
Comment