Link to home
Start Free TrialLog in
Avatar of turtleman2009
turtleman2009

asked on

javascript calculator

I have some formulas that I want processed once you enter your info into the input fields and press the calculate button. I have the formulas working when i hardcode the the info directly into the variables but have had a hard time following what I should do to get everything to work from the input fields.

Could someone show me the modifications that need to be made to get this to work?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
 
 
 
<script type="text/javascript">
var height = 73;
var weight = 100;
var waist = 34;

var idealwaist = height * 0.382;
var idealshoulders = idealwaist * 1.618;
var hips = idealwaist * 1.42;

var waisttoheightratio = height / waist;

var waistdifference = idealwaist - waist;

var calorieintake = weight * (waistdifference - 12);
var maxloss = weight * [waistdifference * (0.005 * (waisttoheightratio - 1))] + 0.3;
var water = weight * 0.025;
function idealwaistfemale() {
	document.write(idealwaist); }
function idealshouldersfemale() {document.write(idealshoulders)}
function idealhipsfemale() {document.write(hips)}
function calorieintakefemale() { if ( 800 < calorieintake)
  {
  document.write(calorieintake);
  }
else
  {
  document.write(800);
  }}

function maxlossfemale() {document.write(maxloss)}

function waterfemale() {document.write(water)}

function fasting() { if ( idealwaist + 6 < waist)
  {
  document.write("72 hours");
  }
else if (idealwaist + 4 < waist )
  {
  document.write("48 hours");
  }
  else if (idealwaist + 1.5 < waist )
  {
  document.write("24 hours");
  }
  
  else
  document.write("24 hours, only as needed");
  }

</script>
 </head><body>

  <FORM NAME="Calculator" METHOD="post">
<P>Height: <INPUT TYPE=TEXT NAME="height" SIZE=10></P>
<P>Weight: <INPUT TYPE=TEXT NAME="weight" SIZE=10></P>
<P>Waist: <INPUT TYPE=TEXT NAME="waist" SIZE=10></P>
<P><INPUT TYPE="button" VALUE="Calculate" name="AddButton"></P>


</FORM>
          
 
                  
1) idealwaist female:<script type="text/javascript">idealwaistfemale();</script><br /><br />
2) idealshoulders female:<script type="text/javascript">idealshouldersfemale();</script><br /><br />
3) idealhips female:<script type="text/javascript">idealhipsfemale();</script><br /><br />
4) Suggested Daily Calorie Intake:<script type="text/javascript">calorieintakefemale();</script><br /><br />
5) Maximal weekly fat loss:<script type="text/javascript">maxlossfemale();</script><br /><br />
6) Possible daily water weight fluctuations:<script type="text/javascript">waterfemale();</script><br /><br />
7) Longest suggested fast:<script type="text/javascript">fasting();</script><br /><br />
</body></html>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of nap0leon
nap0leon

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of turtleman2009
turtleman2009

ASKER

Perfect, thank you for the answer and the explanation!