...

# Need help with calculation code

Deedee
01-04-2004, 02:00 PM
Hi

I need to create a form where the visitor can enter a numeric value in a Form Field and then click on a "calculate button" where the entered value then are subtracted from 2004 and the result divided by 50. This result must then be returned as 4 values:
1 --> the result "to the power of" 0.25
2 --> the result "to the power of" 0.5
3. --> the result "to the power of" 0.75
4. --> the result "to the power of" 1.5

For example if the value entered is 1864 then:
2004 - 1864 / 50 = 2.80 (should be rounded to the neartest = 3)
1. --> 3 to the power of 0.25
2. --> 3 to the power of 0.50 etc

Is there any way to do this?

Thanx!

sciguyryan
01-04-2004, 03:36 PM
Why do you want to do this?

Yes, I think that it is possible.

sciguyryan
01-04-2004, 03:39 PM
Why do you want so man diferent "to the power" parts?

If you tell me then I will help.

beetle
01-04-2004, 03:40 PM
Most everything you need is in the Math object (http://www.w3schools.com/js/js_math.asp)

01-04-2004, 03:49 PM
Hi there Deedee,

Try this little offering...
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<meta content="mshtml 6.00.2800.1264" name="generator" />
<title>DeeDee calculations</title>
<style type="text/css">
/*<![CDATA[*/
body{font-family:arial;font-size:16px;font-weight:bold;}
input{text-align:center;color:#000080;width:60px;margin:2px;}
/*]]>*/
</style>
<script type="text/javascript">
//<![CDATA[
function show()
{
var number=document.getElementById("number").value;
var x=Math.round((2004-number)/50);
var one=Math.pow(x,1/4).toFixed(4);
var two=Math.pow(x,1/2).toFixed(4);
var three=Math.pow(x,3/4).toFixed(4);
var four=Math.pow(x,3/2).toFixed(4);

document.getElementById("resultone").value=one;
document.getElementById("resulttwo").value=two;
document.getElementById("resultthree").value=three;
document.getElementById("resultfour").value=four;
}
//]]>
</script>
<body>
<div id="one">
<form action="">
<div>
<input id="number" type="text"/>Number<br /><br />
<input id="resultone" type="text"/>0.25<br /><br />
<input id="resulttwo" type="text"/>0.5<br /><br />
<input id="resultthree" type="text"/>0.75<br /><br />
<input id="resultfour" type="text"/> 1.5<br /><br />
<input id="button" type="button" value="Show" onclick="show();return false;" />
<input type="reset" value="Reset" name="Reset"/>
</div>
</form>
</div>
</body>
</html>

sciguyryan
01-04-2004, 03:56 PM
Nice code. :)

Deedee
01-04-2004, 03:59 PM
Geeee thanx Coothead! It's exactly what I needed!!

:thumbsup:

01-04-2004, 04:05 PM
You are Welcome :D