PDA

View Full Version : Simple math formula in javascript or html


Corey J
06-25-2006, 06:30 PM
I need a simple mathmatical formula to do width (Ft and inches) x length (ft and inches) and the answer to apear in a sq yards. For my carpet website If anyone could help me id deeply apreciate it. Sorry I relize I posted in the wrong forum

putts
06-26-2006, 09:07 AM
yeah...wrong forum but the answer is that you'd just times them like this...

function compute()
{
var iLenFeet = carpet_form.length_feet.value();
var iLenInch = carpet_form.length_inch.value();
var iWidFeet = carpet_form.width_feet.value();
var iWidInch = carpet_form.width_inch.value();

iLenInch = (iLenFeet*12) + iLenInch
iWidInch = (iWidFeet*12) + iWidInch

iSquare = (iLenInch/36) * (iWidInch/36)
}


Making separate fields for Inches and Feet is the easiest way to do it because then you dont have to worry about getting two values from one field.

waffles
06-26-2006, 10:49 AM
Or if you want to go a PHP route:

<form method="post">
Length feet: <input type="text" name="f" /><br />
Length inches: <input type="text" name="i" /><br />
Width feet: <input type="text" name="f2" /><br />
Width inches: <input type="text" name="i2" /><br />
<input type="submit" name="submit" value="Submit me!" />


<?php

$f=$_POST['f'];
$i=$_POST['i'];
$f2=$_POST['f2'];
$i2=$_POST['i2'];


$d = 1/12;



$q = $i*$d;

$e = $q+$f;

$w = $e/3;

$z = $i2*$d;

$x = $z+$f2;

$c = $x/3;

$v = $c*$w;

echo ($v)

?>

Math works, I tested it. The form is really ugly, but that can be changed. The hard part's done.