View Full Version : simple mathmatical formula
Corey J
06-25-2006, 06:41 PM
I need a simple mathmatical formula in javascript or html to do width (Ft and inches) x length (ft and inches) and the answer to apear in a sq yards. Im not to good at javascript and html could someone help me with the code please
Try to make it first to convert the inserted items into feet and then multiply them with each others and then just convert the square feet into square yards.
waffles
06-25-2006, 07:23 PM
If you can use PHP, there are math operators built into it. You can multiply the inchs by 1/12 (about 0.083333, I don't know how specific you need to be), add that to your feet, and then divide by 3. Do that for both sides and multiply what you get.
--edit--
Got somethign figured out for you.
<?php
$d = 1/12;
$i = 5;
$f = 3;
$i2 = 4;
$f2 = 3;
$q = $i*$d;
$e = $q+$f;
$w = $e/3;
$z = $i2*$d;
$x = $z+$f2;
$c = $x/3;
$v = $c*$w;
echo ($v)
?>
- d is the one constant, 1/12.
- i is inches (and i2)
- f is feet (and f2)
- q is inches multiplied by the constant
- e is the above answer plus the feet
- w is the above answer divided by 3
- z, x, and c do the same in the same order as above
- v is your final answer.
Making the form to get those variables is up to you.
Corey J
06-25-2006, 08:18 PM
I appologize I am not very advanced at all could you explain more or something sorry you prolly hate newbies like me but I really apreciate your help
waffles
06-25-2006, 08:22 PM
Unless you don't like the variable I've establish, that part of the code is about good to go. I'm not sure what you'd have to do with the form to get the variable defined. I defined them inside the code, which isn't something you want to do.
coothead
06-25-2006, 08:38 PM
Hi there Corey453,
try this example, it may suit your requirements...
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>width by length to square yards</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
#container {
width:280px;
padding:6px;
border:3px double #000;
margin:30px auto;
font-family:verdana,arial,helvetica,sans-serif;
font-size:16px;
}
label {
margin:4px;
display:block;
}
-->
</style>
<script type="text/javascript">
<!--
window.onload=function() {
inp=document.getElementsByTagName('input');
df=document.forms[0];
df[5].onclick=function() {
for(c=0;c<inp.length;c++) {
if((inp[c].type=='text')&&(isNaN(inp[c].value))) {
alert('please use the appropriate numbers\nfeet in the feet box\ninches in the inches box');
inp[c].value='';
}
}
for(c=0;c<inp.length;c++) {
if(inp[c].value=='') {
alert('it appears that you have missed box '+(c+1));
return;
}
}
w=parseFloat(df[0].value)/3+parseFloat(df[1].value)/36;
l=parseFloat(df[2].value)/3+parseFloat(df[3].value)/36;
df[4].value=(w*l).toFixed(2);
}
}
//-->
</script>
</head>
<body>
<form action="#">
<div id="container">
<label><input type="text"/>: width feet</label>
<label><input type="text"/>: width inches</label>
<label><input type="text"/>: length feet</label>
<label><input type="text"/>: length inches</label>
<label><input type="text" readonly="readonly" value="0"/>: square yards</label>
<input type="button" value="calculate"/>
<input type="reset" value="clear"/>
</div>
</form>
</body>
</html>
Corey J
06-25-2006, 09:44 PM
thanks that is perfect for what i need
waffles
06-25-2006, 10:20 PM
Since you're using that, be sure to mention that it's a javascript. Enough people have it turned off to mention it.
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.