Need help with calorie script

admin

Administrator
Staff member
i'm having trouble with the popup box for gender

every time i hit the calculate button the popup selection reverts to "male" and the function will not return the "female"
numbers. this doesn't happen for my other popup "muscle" and yet they look the same.

any idea what i've done wrong?
here's the script i wrote: (the entire html document is attached as a txt file)

var ht_feet, ht_inches, current_weight, desired_weight, height, age, muscle, calorie_intake;

function calc_calories() {
current_weight = Number(document.calories.current_weight.value);
desired_weight = Number(document.calories.desired_weight.value);
height = Number(document.calories.ht_feet.value) * 12 + Number(document.calories.ht_inches.value);
age= Number(document.calories.age.value);

if (window.document.calories.muscle.options[0].selected == true) // coefficient for muscularity
{
muscle = .93;
} else {
if (window.document.calories.muscle.options[1].selected == true) {
muscle = 1;
} else {
if (window.document.calories.muscle.options[2].selected == true) {
muscle = 1.07;
} else {
alert ("Please enter muscularity")
}
}
}

if (age<18) {
alert("You must be 18 or older to get calorie recommendations");
}

if (window.document.calories.gender.options[0].selected = true) { // if male
calorie_intake = muscle * (1.25 * (66 + (6.23 * desired_weight) + (12.7 * height) - (6.8 * (age +1))));
} else { // if female
calorie_intake = muscle * (1.25 * (665 + (4.36 * desired_weight) + (4.32 * height) - (4.7 * (age+1))));
}

document.calories.rec_calories.value = Math.round(calorie_intake);

}

thanks much!

mark
 
Back
Top