ApniGang
05-16-2009, 11:17 AM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>untitled</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<script type="text/javascript">
function setEvent(){
var but, i=1;
while(but=document.getElementById('calc_'+(i++))){
but.onclick=calculate
}
}
function calculate(){
var f=this.form, grandtotV=0, j=1, i=1, but;
while(but=document.getElementById('calc_'+(j++))){
var oQty=f['qty_'+i];
var oPrice=f['price_'+i];
var oTaxrate=f['taxrate_'+i];
var oSubtotal=f['subtotal_'+i];
var oTax=f['tax_'+i];
var oTotal=f['total_'+i];
i++;
var subV=Number(oQty.value)*Number(oPrice.value);
var taxV=subV*Number(oTaxrate.value);
var totV=subV+subV*Number(oTaxrate.value);
grandtotV+=totV;
oSubtotal.value=subV==0?'':subV.toFixed(2);
oTax.value=taxV==0?'':taxV.toFixed(2);
oTotal.value=totV==0?'':totV.toFixed(2);
}
f['gradtotal'].value=grandtotV.toFixed(2);
}
onload=setEvent
</script>
</head>
<body>
<form action="">
<div>
Quantity: <input type="text" name='qty_1'><br>
Price: <input type="text" name='price_1'><br>
Tax Rate: <input type="text" name="taxrate_1" value="0.00"/><br>
Subotal: <input type="text" name="subtotal_1" readonly="readonly"><br>
Tax: <input type="text" name="tax_1" readonly="readonly"><br>
Total: <input type="text" name="total_1" readonly="readonly"><br>
<input type="button" value="Calculate" id="calc_1">
</div>
<div>
Quantity: <input type="text" name='qty_2'><br>
Price: <input type="text" name='price_2'><br>
Tax Rate: <input type="text" name="taxrate_2" value="0.0825"/><br>
Subotal: <input type="text" name="subtotal_2" readonly="readonly"><br>
Tax: <input type="text" name="tax_2" readonly="readonly"><br>
Total: <input type="text" name="total_2" readonly="readonly"><br>
<input type="button" value="Calculate" id="calc_2">
</div>
<div>
Quantity: <input type="text" name='qty_3'><br>
Price: <input type="text" name='price_3'><br>
Tax Rate: <input type="text" name="taxrate_3" value="0.0825"/><br>
Subotal: <input type="text" name="subtotal_3" readonly="readonly"><br>
Tax: <input type="text" name="tax_3" readonly="readonly"><br>
Total: <input type="text" name="total_3" readonly="readonly"><br>
<input type="button" value="Calculate" id="calc_3">
</div>
Grand total:<input type="text" name="gradtotal" readonly="readonly">
</form>
</body>
</html>
i want without clicking on calculate button answer will automatic display like Grand total in this code.
thank you
<html>
<head>
<title>untitled</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<script type="text/javascript">
function setEvent(){
var but, i=1;
while(but=document.getElementById('calc_'+(i++))){
but.onclick=calculate
}
}
function calculate(){
var f=this.form, grandtotV=0, j=1, i=1, but;
while(but=document.getElementById('calc_'+(j++))){
var oQty=f['qty_'+i];
var oPrice=f['price_'+i];
var oTaxrate=f['taxrate_'+i];
var oSubtotal=f['subtotal_'+i];
var oTax=f['tax_'+i];
var oTotal=f['total_'+i];
i++;
var subV=Number(oQty.value)*Number(oPrice.value);
var taxV=subV*Number(oTaxrate.value);
var totV=subV+subV*Number(oTaxrate.value);
grandtotV+=totV;
oSubtotal.value=subV==0?'':subV.toFixed(2);
oTax.value=taxV==0?'':taxV.toFixed(2);
oTotal.value=totV==0?'':totV.toFixed(2);
}
f['gradtotal'].value=grandtotV.toFixed(2);
}
onload=setEvent
</script>
</head>
<body>
<form action="">
<div>
Quantity: <input type="text" name='qty_1'><br>
Price: <input type="text" name='price_1'><br>
Tax Rate: <input type="text" name="taxrate_1" value="0.00"/><br>
Subotal: <input type="text" name="subtotal_1" readonly="readonly"><br>
Tax: <input type="text" name="tax_1" readonly="readonly"><br>
Total: <input type="text" name="total_1" readonly="readonly"><br>
<input type="button" value="Calculate" id="calc_1">
</div>
<div>
Quantity: <input type="text" name='qty_2'><br>
Price: <input type="text" name='price_2'><br>
Tax Rate: <input type="text" name="taxrate_2" value="0.0825"/><br>
Subotal: <input type="text" name="subtotal_2" readonly="readonly"><br>
Tax: <input type="text" name="tax_2" readonly="readonly"><br>
Total: <input type="text" name="total_2" readonly="readonly"><br>
<input type="button" value="Calculate" id="calc_2">
</div>
<div>
Quantity: <input type="text" name='qty_3'><br>
Price: <input type="text" name='price_3'><br>
Tax Rate: <input type="text" name="taxrate_3" value="0.0825"/><br>
Subotal: <input type="text" name="subtotal_3" readonly="readonly"><br>
Tax: <input type="text" name="tax_3" readonly="readonly"><br>
Total: <input type="text" name="total_3" readonly="readonly"><br>
<input type="button" value="Calculate" id="calc_3">
</div>
Grand total:<input type="text" name="gradtotal" readonly="readonly">
</form>
</body>
</html>
i want without clicking on calculate button answer will automatic display like Grand total in this code.
thank you