# 2dp output restriction, and loop calculation required, with form

**URL:** <https://forum.kirupa.com/t/2dp-output-restriction-and-loop-calculation-required-with-form/290779>\
**Category:** Uncategorized\
**Created:** [June 19, 2009, 2:11pm UTC](https://forum.kirupa.com/t/2dp-output-restriction-and-loop-calculation-required-with-form/290779 "2009-06-19T14:11:17Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![banjax1](https://avatars.discourse-cdn.com/v4/letter/b/3d9bf3/32.png) [@banjax1](https://forum.kirupa.com/u/banjax1)\
**Post date:** [June 19, 2009, 2:11pm UTC](https://forum.kirupa.com/t/2dp-output-restriction-and-loop-calculation-required-with-form/290779/1 "2009-06-19T14:11:17Z")

</div>

Hello everyone.

I have a form that I have developed and am stuck. The outputs that are displayed should be in 2 decimal places. I have searched for ways to do this, but to no avail have they worked for my piece of code. Please have a look and if you could, suggest a way of making this output work for me as needed. 😕

The form is used to calculate savings and is working as expected (giving me the correct results from the calculated inputs), but only fully after clicking 4 times. I guess this is because the form needs the previous outputs to go ahead with the next calculation, could you also suggest a method that the calculation could loop and complete all calculations with only one click? I’m sure there is a way, I just have no clue how to.

[SIZE=“5”]Code[/SIZE]

[SIZE=“5”]JavaScript[/SIZE]

```auto
</script>

<script language="JavaScript">

function showpay() {
 if ((document.calc.a.value == null || document.calc.a.value.length == 0) ||
     (document.calc.b.value == null || document.calc.b.length == 0) ||
     (document.calc.c.value == null || document.calc.c.value.length == 0) ||
     (document.calc.d.value == null || document.calc.d.value.length == 0) ||
     (document.calc.e.value == null || document.calc.e.value.length == 0))
      
 { alert("Please enter all values");
 }
 else
 {
 var aa = document.calc.a.value;
 var ab = document.calc.b.value;
 var ac = document.calc.c.value;
 var ad = document.calc.d.value;
 var ae = document.calc.e.value;

 var af = document.calc.f.value;
 var ag = document.calc.g.value;
 var ah = document.calc.h.value;
  
 var ai = document.calc.i.value;
 var aj = document.calc.j.value;
 var ak = document.calc.k.value;

 var al = document.calc.l.value;
 var am = document.calc.m.value;
 var an = document.calc.n.value;
 var ao = document.calc.o.value;
 
 var ap = document.calc.p.value;
 var aq = document.calc.q.value;
 var ar = document.calc.r.value;
 var as = document.calc.s.value;
 
 var at = document.calc.t.value;
 var au = document.calc.u.value;
 var av = document.calc.v.value;
 var aw = document.calc.w.value;

// calculations

 document.calc.f.value = ab * ac;
 document.calc.g.value = ac * ad;
 document.calc.h.value = ae / ag;
 
 document.calc.i.value = ah / 4.3;
 document.calc.j.value = ai / 4.3;
 document.calc.k.value = ai / 52;
 
 document.calc.l.value = aa * 1;
 document.calc.m.value = "$" + aa * af;
 document.calc.n.value = ad * af;
 document.calc.o.value = "$" + aa * ag;
 
 document.calc.p.value = aa * 4.3;
 document.calc.q.value = "$" + af * ap; 
 document.calc.r.value = ad * ap;
 document.calc.s.value = "$" + ag * ap;
 
 document.calc.t.value = ap * 12; 
 document.calc.u.value = "$" + af * at;
 document.calc.v.value = ad * at;
 document.calc.w.value = "$" + (ag * at);

 }
}

</script>

```

[SIZE=“5”]HTML Output[/SIZE] Excuse the tables please.

```auto
<form name=calc method=POST>
<table class="caltable" width=84% border=0>
<tr>
  <th height="81" colspan="2">&nbsp;</th>
  <td colspan="3"><div align="left">Enter your data in the white fields to work out cost savings <br /> of a Bioptics Specimen Radiography system, or test different scenarios by varying the inputs.</div></td>
  </tr>
<tr><td height="42" colspan="2" align=left><h3>Costs</h3>
<th width=18%>&nbsp;</th>
  <th width=18%></th>
<th width=18%>&nbsp;</th>
</tr>

<tr height="20%"><td height="50" colspan="3" valign="top"><strong>Surgeries Per Week </strong><br>
     How many breast surgeries do you perform?</td>
  <td align=right valign="top"><input type=text name=a size=13></td>
  <td align=right valign="top">&nbsp;</td>
</tr>
<tr>
  <td height="30" colspan="3" valign="top"><strong>Average Minutes Per Surgery </strong></td>
  <td
align=right valign="top"><input type=text name=b size=13></td>
  <td
align=right valign="top">&nbsp;</td>
</tr>
<tr>
  <td height="30" colspan="3" valign="top"><strong>Average Cost Per Surgery </strong></td>
  <td align=right valign="top"><input name=c type=text size=13></td>
  <td align=right valign="top">&nbsp;</td>
</tr>
<tr>
  <td height="66" colspan="3" valign="top"><strong>Minutes Saved Per Surgery </strong> <br/ > 
    How many minutes can you save per surgery if you 
don't<br> have to send the specimen out for imaging?</td>
  <td 
align=right valign="top"> <input type=text name=d size=13></td>
  <td 
align=right valign="top">&nbsp;</td>
</tr>
<tr>
  <td height="48" colspan="3" valign="top"><strong>Cost of Digital Equipment</strong> <br/ >
  List price quoted by Bioptics sales representative.</td>
  <td 
  align=right valign="top"> <input name=e type=text size=13></td>
  <td 
  align=right valign="top">&nbsp;</td>
</tr>
<tr>
  <td width="25%" height="35" align=center>&nbsp;</td>
  <td width="21%" height="35" align=center>&nbsp;</td>
  <td height="35" align=center>&nbsp;</td>
  <td height="35" align=center valign="top"><input type="button" onClick='showpay()' value=Calculate> </td>
  <td height="35" align=center valign="top"><input name="reset" type=reset value=Reset></td>
</tr>
<tr>
  <td height="33" colspan="2" align=left valign="top"><h3>Results</h3></td>
  <td align=right valign="top">&nbsp;</td>
  <td align=right valign="top">&nbsp;</td>
  <td align=right valign="top">&nbsp;</td>
</tr>
<tr>
  <td height="30" colspan="3" valign="top"><strong>Cost of Surgeries</strong> </td>
  <td align=right valign="top"> <input type=text name=f size=13></td>
  <td align=right>&nbsp;</td>
</tr>
<tr>
  <td height="30" colspan="3" valign="top"><strong>Amount saved per surgery</strong> </td>
  <td align=right valign="top"><input type=text name=g size=13></td>
  <td align=right>&nbsp;</td>
</tr>
<tr>
  <td height="30" colspan="3" valign="top"><strong>Surgeries Until Investment is recovered</strong> </td>
  <td align=right valign="top"><input type=text name=h size=13></td>
  <td align=right>&nbsp;</td>
</tr>
<tr>
  <td height="45" colspan="2" rowspan="2" valign="top"><strong>Time Until Investment is recovered</strong></td>
  <td align=right valign="top"><input type=text name=i size=13></td>
  <td align=right valign="top"><input type=text name=j size=13></td>
  <td align=right valign="top"><input type=text name=k size=13></td>
</tr>
<tr>
  <td align=center valign="top">Weeks</td>
  <td align=center valign="top">Months</td>
  <td align=center valign="top">Years</td>
</tr>
<tr>
  <td height="32" colspan="2" align=left><h3>Savings</h3></td>
  <td align=right valign="top">&nbsp;</td>
  <td align=right valign="top">&nbsp;</td>
  <td align=right valign="top">&nbsp;</td>
</tr>
<tr>
  <td height="35" align=center>&nbsp;</td>
  <td height="35" align=center><strong>Total Number<br />of Surgeries</strong></td>
  <td height="35" align=center><strong>Total Cost<br />of Surgeries</strong></td>
  <td height="35" align=center><strong>Total Minutes<br />Saved</strong></td>
  <td height="35" align=center><strong>Total Amount<br />Saved</strong></td>
</tr>
<tr>
  <td width="25%" height="30" valign="top"><strong>Weekly</strong></td>
  <td align=right valign="top"><input type=text name=l size=13></td>
  <td align=right valign="top"><input type=text name=m size=13></td>
  <td align=right valign="top"><input type=text name=n size=13></td>
  <td align=right valign="top"><input type=text name=o size=13></td>
</tr>
<tr>
  <td width="25%" height="30" valign="top"><strong>Monthly</strong></td>
  <td align=right valign="top"><input type=text name=p size=13></td>
  <td align=right valign="top"><input type=text name=q size=13></td>
  <td align=right valign="top"><input type=text name=r size=13></td>
  <td align=right valign="top"><input type=text name=s size=13></td>
</tr>
<tr>
  <td width="25%" height="33" valign="top"><strong>Annually</strong></td>
  <td align=right valign="top"><input type=text name=t size=13></td>
  <td align=right valign="top"><input type=text name=u size=13></td>
  <td align=right valign="top"><input type=text name=v size=13></td>
  <td align=right valign="top"><input type=text name=w size=13></td>
</tr>
<tr>
  <td height="30" align=center>&nbsp;</td>
  <td align=right valign="top">&nbsp;</td>
  <td align=right valign="top">&nbsp;</td>
  <td align=right valign="top">&nbsp;</td>
  <td height="45" align=center valign="top"><img src="images/print_btn_up.png" alt="" name="Pictures" width="100" height="33" align="top"></td>
</tr>
</table>
</form>

```

Please excuse the table.

Many thanks guys. Cheers,

DS
