PHP Board Footage Calculator

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rziegler
Forum Newbie
Posts: 2
Joined: Thu Sep 17, 2009 1:44 pm

PHP Board Footage Calculator

Post 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
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: PHP Board Footage Calculator

Post 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?
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: PHP Board Footage Calculator

Post 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);
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
rziegler
Forum Newbie
Posts: 2
Joined: Thu Sep 17, 2009 1:44 pm

Re: PHP Board Footage Calculator

Post 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>
Post Reply