Tally Totals

[Total: 0    Average: 0/5]

This shows how to tally the results of math in forms.

Body Code:

<script>
function doIt(_f)
{
  if(_f.q1.value!="" && _f.c1.value!="")_f.t1.value=parseInt(parseInt(parseInt(_f.q1.value)*parseFloat(_f.c1.value)*100)/100);
  else _f.t1.value="0";
  if(_f.q2.value!="" && _f.c2.value!="")_f.t2.value=parseInt(parseInt(parseInt(_f.q2.value)*parseFloat(_f.c2.value)*100)/100);
  else _f.t2.value="0";
  if(_f.q3.value!="" && _f.c3.value!="")_f.t3.value=parseInt(parseInt(parseInt(_f.q3.value)*parseFloat(_f.c3.value)*100)/100);
  else _f.t3.value="0";
  _f.total.value=parseInt(_f.t1.value)+parseInt(_f.t2.value)+parseInt(_f.t3.value);
}
</script>
<form name=exf1>
<table>
<tr><td>1: Quantity <input type=text name=q1></td><td>Cost per Item<input type=text name=c1></td><td>Total<input type=text name=t1></td></tr>
<tr><td>2: Quantity <input type=text name=q2></td><td>Cost per Item<input type=text name=c2></td><td>Total<input type=text name=t2></td></tr>
<tr><td>3: Quantity <input type=text name=q3></td><td>Cost per Item<input type=text name=c3></td><td>Total<input type=text name=t3></td></tr>
</table>
<BR><BR>
Total Cost:<input type=text name=total>
<BR><BR>
<input type=button onclick="doIt(this.form)" value="Compute">
</form>

Times Viewed: 0

Leave a Reply

Your email address will not be published. Required fields are marked *