BMR计算器:在BMR计算器中用瘦体重代替体重

BMR calculator: Substituting body mass with lean body mass in BMR calculator

本文关键字:BMR 计算器      更新时间:2023-09-26

我使用美国海军公式修改了一个体脂计算器。计算器提供1.BMR2.最低热量要求3.体脂

计算器运行良好,但我希望基础代谢率利用瘦体重,而不是体重(以表格形式提供)

i在BMR计算之前添加:wt1=wt-(wt/100*fatPercent)。

控制台没有显示任何错误,但我在执行脚本时没有得到任何结果。不知道如何更正。

提前感谢

Javascript代码

    <script type="text/javascript">
<!--
function Calculate()
{
        var ht = parseFloat(document.cal_frm.txtHeight.value);
        var nk = parseFloat(document.cal_frm.txtNeck.value);
        var wa = parseFloat(document.cal_frm.txtWaist.value);
        var hp = parseFloat(document.cal_frm.txtHip.value);
        var wt = parseFloat(document.cal_frm.txtWeight.value);
        var ag = parseInt(document.cal_frm.txtAge.value);
        var sexf=false;
        if (document.cal_frm.opGender.value == "1"){sexf=true;}
        if (document.cal_frm.opHeight.value == "1") {ht = ht * 2.54;}
        if (document.cal_frm.opNeck.value == "1") {nk = nk * 2.54;}
        if (document.cal_frm.opWaist.value == "1") {wa = wa * 2.54;}
        if (document.cal_frm.opHip.value == "1") {hp = hp * 2.54;}
        if (document.cal_frm.opWeight.value == "1") {wt = wt * 0.4536;}
        document.getElementById('feedback').innerHTML='';
        var errors='';
        if ((ht < 122) || (ht > 230) || isNaN(ht)){
        err=((document.cal_frm.opHeight.value == "1")? '48inches to 90inches' : '122cm to 230cm');
errors+='Enter height between '+err+'!n';}
        if ((nk < 10) || (nk > 100) || isNaN(nk)){
        err=((document.cal_frm.opNeck.value == "1")? '6inches to 20inches' : '15cm to 50cm');
errors+='Enter neck between '+err+'!n';}
        if ((wa < 20) || (wa > 200) || isNaN(wa)){
        err=((document.cal_frm.opWaist.value == "1")? '20inches to 80inches' : '50cm to 150cm');
errors+='Enter waist between '+err+'!n';}
        if ((wt < 30) || (wt > 150) || isNaN(wt)){
        err=((document.cal_frm.opWeight.value == "1")? '67lb to 333lb' : '30Kg to 150Kg');
errors+='Enter weight between '+err+'!n';}
        if ((ag < 19) || (ag > 70) || isNaN(ag)){
        err='19yrs to 70yrs';
errors+='Enter age between '+err+'!n';}
        if (sexf==true){
            if ((hp < 50) || (hp > 200) || isNaN(hp)){
            err=((document.cal_frm.opHip.value == "1")? '20inches to 100inches' : '50cm to 250cm');
errors+='Enter hip between '+err+'!n';}}
        if(errors){
            alert('The following error(s) occurred:n'+errors);
            return;}
        var BMR;
        var fatpercent;
        if (sexf==true) {
            fatPercent = 495 / (1.29579 - 0.35004 * (logten(wa + hp - nk)) + 0.221 * (logten(ht))) - 450;   
            wt1 = wt-(wt/100*fatPercent) /*added below code to substitute weight with lean body mass in the below calculation*/
            BMR = 655 + (9.6 * wt1) + (1.8 * ht) - (4.7 * ag);
        }
        else{
            fatPercent = 495 / (1.0324 - 0.19077 * (logten(wa - nk)) + 0.15456 * (logten(ht))) - 450;
            wt1 = wt-(wt/100*fatPercent)/*added below code to substitute weight with lean body mass in the below calculation*/
            BMR = 66 + (13.7 * wt1) + (5 * ht) - (6.8 * ag);
        }
        BMR=Math.round(BMR*10)/10;
        fatPercent = (Math.round(fatPercent*10))/10;
        var dailyCal;
        if (document.cal_frm.opActivity.value == "0") {dailyCal = BMR * 1.2;}
        if (document.cal_frm.opActivity.value == "1") {dailyCal = BMR * 1.375;}
        if (document.cal_frm.opActivity.value == "2") {dailyCal = BMR * 1.55;}
        if (document.cal_frm.opActivity.value == "3") {dailyCal = BMR * 1.725;}
        if (document.cal_frm.opActivity.value == "4") {dailyCal = BMR * 1.9;}
if (document.cal_frm.opWeight.value == "1") { 
        document.getElementById('feedback').innerHTML = "<p>Your BMR is: " + BMR + "<br />" + "Minimum Calorie 
requirement is: " + (Math.round(dailyCal)) + ";<br />" + "Your Body Fat is " + fatPercent + "%." + ";<br /></p>";
}
function logten(v){
    return (Math.log(v)/Math.log(10));
}
function resetAll(){
document.getElementById('feedback').innerHTML ='';
}
}
-->
</script>

HTML代码

<form name="cal_frm" id="cal_frm" style="width:400px; margin:20px 10px 20px 10px;" onsubmit="return false">
<table style="width:400px; margin:0px 10px 20px 10px;">
<tr><td style="width: 275px;">
<table id="cal_data">
<tr>
<td style="padding-left:5px;">Height:</td>
<td><input class="cal_text" type="text" name="txtHeight" size="20" ></td>
<td><select class="cal_option" name="opHeight">
<option value="0">Cm</option>
<option value="1">Inch</option>
</select></td>
</tr>
<tr>
<td style="padding-left:5px;">Neck:</td>
<td><input class="cal_text" type="text" name="txtNeck" size="20" ></td>
<td><select class="cal_option" name="opNeck">
<option value="0">Cm</option>
<option value="1">Inch</option>
</select></td>
</tr>
<tr>
<td style="padding-left:5px;">Waist:</td>
<td><input class="cal_text" type="text" name="txtWaist" size="20" ></td>
<td><select class="cal_option" name="opWaist">
<option value="0">Cm</option>
<option value="1">Inch</option>
</select></td>
</tr>
<tr>
<td style="padding-left:5px;">Hip (Female):</td>
<td><input class="cal_text" type="text" name="txtHip" size="20" ></td>
<td><select class="cal_option" name="opHip">
<option value="0">Cm</option>
<option value="1">Inch</option>
</select></td>
</tr>
<tr>
<td style="padding-left:5px;">Weight:</td>
<td><input class="cal_text" type="text" name="txtWeight" size="20" ></td>
<td><select class="cal_option" name="opWeight">
<option value="0">Kg</option>
<option value="1">Pound</option>
</select></td>
</tr>
</table>
</td>
<td style="padding: 10px 0 0 10px;">
Gender:<br >
<select class="cal_option" style="width:72%;border: solid 1px silver;" name="opGender">
<option value="0">Male</option>
<option value="1">Female</option>
</select><br ><br >
Age:<br >
<input class="cal_text" style="width:60%;border: solid 1px silver;" type="text" name="txtAge" size="20" > yrs.
</td>
</tr>
<tr>
<td colspan="2" style="padding:10px 0 10px 0;"><span style="padding:0 2px;">Activity:</span>
<select id="Select7" class="cal_option" style="width:80%; border:1px solid silver;" name="opActivity">
<option selected="selected" value="0">Sedentary (Very little or no exercise)</option>
<option value="1">Lightly active (light exercise/sports 1-3 days/week)</option>
<option value="2">Moderately active (moderate exercise/sports 3-5 days/week)</option>
<option value="3">Very active (hard exercise/sports 6-7 days a week)</option>
<option value="4">Extra active (very hard exercise/sports & physical job or 2x training)</option>
</select>
</td>
</tr>
<tr>
<td id="feedback" colspan="2" style="padding:0 0 5px 0; font-family:arial; font-size:11px; color:#333333;" ><a 
style="font-size:1px;color:#ffffff;line-height:1%;" href="http://ramui.com">http://ramui.com</a></td>
</tr>
<tr>
<td colspan="2">
<input onclick="Calculate()" class="cal_button" type="button" value="Calculate" >&nbsp;<input type="reset" 
class="cal_button" value="Reset" onclick="resetAll()" ></td>
</tr></table>
</form>

只有当重量以磅为单位指定时,才能输出结果。