Hi all,
I have a script I am working on (thanks to people on this forum). I would like to remove the “calculate” buttons and use onBlur for each price textbox to run the function… here is what I have so far:
<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
var oPrice=f[‘price_’+i];
i++;
var subV=Number(oQty.value)*Number(oPrice.value);
var totV=subV;
grandtotV+=totV;
}
f[‘partstotal’].value=grandtotV.toFixed(2);
f[‘tax’].value = (f[‘partstotal’].value
f[‘gtotal’].value = ((f[‘partstotal’].value * f[‘taxrate’].value) + grandtotV).toFixed(2);
}
onload=setEvent
</script>
<form action=””>
Quantity: <input type=”text” name=’qty_1′><br>
Price: <input type=”text” name=’price_1′ onBlur=”javascript:calculate()”><br>
<input type=”button” value=”Calculate” id=”calc_1″>
<br><br>
Quantity: <input type=”text” name=’qty_2′><br>
Price: <input type=”text” name=’price_2′ onBlur=”javascript:calculate()”><br>
<input type=”button” value=”Calculate” id=”calc_2″>
<br><br>
Quantity: <input type=”text” name=’qty_3′><br>
Price: <input type=”text” name=’price_3′ onBlur=”javascript:calculate()”><br>
<input type=”button” value=”Calculate” id=”calc_3″>
<br><br>
Tax Rate: <input type=”text” name=”taxrate” value=”0.0825″>
<br>Tax: <input type=”text” name=”tax” readonly=”readonly”>
<br>Parts Total: <input type=”text” name=”partstotal” readonly=”readonly”>
<br>Grand Total:<input type=”text” name=”gtotal” readonly=”readonly”>
</form>