Skip to main content
Inspiring
March 30, 2010
Question

Cost Calculator

  • March 30, 2010
  • 2 replies
  • 873 views

Hello,

I am creating a cost calculator for a hobby of mine and was wondering what would be some good ways of handling it. It does not have to be real fancy and I would like it to be contained to one page. Ideally I want to fill in the blanks, click the calculate button and then it will display the results. Here is my base that I am working with. I know how to do the actual calculating routines, I just need some input on some good ways to go about it. TIA.

<cfform name="form1" id="form1" method="post" action="">
<u>Calculator</u><br />
<br />
<table width="64%" border="0" cellpadding="0">
  <tr>
    <td width="31%"><div align="center"><strong>Component</strong></div></td>
    <td width="31%"><div align="center"><strong>Quantity</strong></div></td>
    <td width="38%"><div align="center"><strong>Cost</strong></div></td>
  </tr>
  <tr>
    <td>Powder(lbs)</td>
    <td>
      <cfinput type="text" name="PowderQty" id="PowderQty">
    </td>
    <td>$
    <cfinput type="text" name="PowderCost" id="PowderCost"></td>
  </tr>
  <tr>
    <td>Powder Charge(grains)</td>
    <td><cfinput type="text" name="PowderCharge" id="PowderCharge"></td>
    <td> </td>
  </tr>
  <tr>
    <td>Primer</td>
    <td><cfinput type="text" name="PrimerQty" id="PrimerQty"></td>
    <td>$
    <cfinput type="text" name="PrimerCost" id="PrimerCost"></td>
  </tr>
  <tr>
    <td>Case</td>
    <td><cfinput type="text" name="CaseQty" id="CaseQty"></td>
    <td>$
    <cfinput type="text" name="CaseCost" id="CaseCost"></td>
  </tr>
  <tr>
    <td>Bullet</td>
    <td><cfinput type="text" name="BulletQty" id="BulletQty"></td>
    <td>$
    <cfinput type="text" name="BulletCost" id="BulletCost"></td>
  </tr>
</table>
<p>
  <cfinput type="button" name="Calculate" value="Calculate" id="Calculate" >
</p>
Cost/Round: Show calculations when calc button is pressed<br />
Cost/20:Show calculations when calc button is pressed<br />
Cost/50:Show calculations when calc button is pressed<br />
Cost/100:Show calculations when calc button is pressed<br />
Cost/500:Show calculations when calc button is pressed<br />
Cost/1000:Show calculations when calc button is pressed<br />

</cfform>

This topic has been closed for replies.

2 replies

Inspiring
April 1, 2010

I agree that JavaScript is probably what you want to use here.  (There are ways to invoke it from CFML tags.)  Basically, this will avoid sending away for a new screen when the user presses the button.  Instead, the JavaScript will make the calculation and display it directly.

Inspiring
March 30, 2010

I suggest you do something to ensure that everything you are trying to do math with is actually a number and you don't try to divide by 0.

rmorganAuthor
Inspiring
March 30, 2010

Thanks. Right, I understand that. Maybe I was not clear in my statement. The actual math part, I understand what needs to be done, I guess what I should have said is what is the best way to kick off the calculations after the calculate button is pressed and to display the dollar amounts for the cost/qty at the bottom of the form.

Inspiring
March 30, 2010

If it were me, I'd use javascript.