Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

# Thread: Need help with calculation code

1. ## Need help with calculation code

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!

• Why do you want to do this?

Yes, I think that it is possible.

• Why do you want so man diferent "to the power" parts?

If you tell me then I will help.

• Most everything you need is in the Math object

• Hi there Deedee,

Try this little offering...
Code:
```<!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;" />&#160;
<input type="reset" value="Reset" name="Reset"/>
</div>
</form>
</div>
</body>
</html>```

• Nice code.

• Geeee thanx Coothead! It's exactly what I needed!!

• You are Welcome

•

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•