Page 1 of 1

PHP Board Footage Calculator

Posted: Thu Sep 17, 2009 1:52 pm
by rziegler
Is there a way I can calculate ONE simple formula based on 3 text inputs?

I want a form that requires the user to put in the following:

Thickness (in)
Width (in)
Length (ft)

Then press "Submit"

Then Spit out a value within the same page in a field labeled "Total BF"

The formula applied to the Thickness, Width, and Length fields

is (Thick * Width * Length/12) = Total BF


Any help will... help!

Thanks!
Ryan

Re: PHP Board Footage Calculator

Posted: Thu Sep 17, 2009 1:54 pm
by jackpf
You can do this with javascript. Or PHP. Your choice...they'll both have a very similar way of doing it.

What part are you having trouble with..? What have you got so far?

Re: PHP Board Footage Calculator

Posted: Thu Sep 17, 2009 2:10 pm
by pickle
With javascript, it could be as simple as:

Code: Select all

var length = document.getElementById('length').val();
var width = document.getElementById('width').val();
var thickness = document.getElementById('thickness').val();
 
document.getElementById('total').val(length * width * thickness/12);

Re: PHP Board Footage Calculator

Posted: Thu Sep 17, 2009 3:44 pm
by rziegler
I've never really used php or javascript much... only when I have someone elses help! I thank you for taking the time to look at this code to make it work. Thanks!

Code: Select all

<body>  
<script>
var Length = document.getElementById('Length').val();
var Width = document.getElementById('Width').val();
var Thickness = document.getElementById('Thickness').val();
var Pieces = document.getElementById('Pieces').val();
 
document.getElementById('TotalBF').val(Pieces * Length * Width * Thickness/12);
</script>
<body>  <table width="442" border="0" cellpadding="0">
    <tr>
      <td width="284"><form action="bfcalc.php" method="get" name="bfcalc" class="style1" id="bfcalc">
        <p align="right">
        <label>
       Thickness (in) 
       <input type="text" name="Thickness" id="Thickness" tabindex="1" />
        </label></p>
        <p align="right">
          <label>Width (in)
          <input type="text" name="Width" id="Width" tabindex="2" />
          </label>
        </p>
        <p align="right">
          <label>Length (ft)
          <input type="text" name="Length" id="Length" tabindex="3" />
          </label>
        </p>
        <p align="right">
          <label>Pieces
          <input type="text" name="Pieces" id="Pieces" tabindex="4" />
          </label>
        </p>
        <p align="center">
          <input type="submit" name="Calculate" id="Calculate" value="Calculate" tabindex="6" />
        </p>
        <p align="right">
          <label>Total Board Feet
          <input type="text" name="TotalBF" id="TotalBF" tabindex="8" />
          </label>
        </p>
 
      </form></td>
      <td width="152">&nbsp;</td>
    </tr>
  </table>
</body>