Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13
  1. #1
    New to the CF scene
    Join Date
    Dec 2007
    Posts
    6
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Calculator not working

    Hi I'm trying to provide visitors to my site a way to calculate their RMR (resting metabolic rate), by putting in their height, weight, and age. I don't really know javascript so I've been fooling around with different attempts to come up with the proper code, however I'm still not getting it. When I hit calculate it doesn't do anything. Any suggestions would be greatly appreciated, thanks. Here's my code:

    <html>
    <head>
    <script language="JavaScript">
    <!-- hide this script from old browsers
    function rmrcalc(form)
    {
    var age = document.form.age.value;
    var height = document.form.height.value;
    var weight = document.form.weight.value;
    rmr = ((5.0033)*height + (13.751)*weight – age*(6.755) + 66.473);
    form.rmrcalc.value = cal;
    }
    // done hiding from old browsers -->
    </script>
    </head>
    <body>
    <FORM>
    <h2>RMR Calculator</h2>
    Enter Weight, Height, and Age:
    <INPUT NAME="height" VALUE="0" MAXLENGTH="15" SIZE=15>
    <p>
    <INPUT NAME="weight" VALUE="0" MAXLENGTH="15" SIZE=15>
    <p>
    <INPUT NAME="age" VALUE="0" MAXLENGTH="15" SIZE=15>
    <p>
    Click this button to calculate RMR:
    <INPUT NAME="rmrcalc" VALUE="Calculate" TYPE=BUTTON onClick=”computeform(this.form)”>
    Your RMR is:
    <INPUT NAME="RMR" READONLY SIZE=15>
    </FORM>
    </body>
    </html>

  • #2
    Banned
    Join Date
    May 2006
    Location
    England
    Posts
    664
    Thanks
    0
    Thanked 84 Times in 84 Posts
    Quote Originally Posted by nattauhi View Post
    Hi I'm trying to provide visitors to my site a way to calculate their RMR (resting metabolic rate), by putting in their height, weight, and age. I don't really know javascript so I've been fooling around with different attempts to come up with the proper code, however I'm still not getting it. When I hit calculate it doesn't do anything. Any suggestions would be greatly appreciated, thanks. Here's my code:

    function rmrcalc(form)
    .
    .
    .
    onClick=”computeform(this.form)”>
    A good starting point would be to call the function that you wrote, in favour of one that isn't there.
    I recommend that you familiarise yourself with the error console, which is essential to successful scripting.

  • #3
    Senior Coder coothead's Avatar
    Join Date
    Jan 2004
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    1,680
    Thanks
    0
    Thanked 230 Times in 225 Posts
    Hi there nattauhi,

    here is you code somewhat corrected.
    This means that the script now performs but the output is pretty well meaningless.
    You will have to work on your weight,height and age variables to ensure that they are specific.
    Is the height going to be measured in inches or centimeters?
    Is the weight going to be measured in grams or ounces pounds or kilograms?
    What will happen if text is input instead of numbers?
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
       "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    
    <script type="text/javascript">
    <!-- hide this script from old browsers
    function computeform(form){
    age=form.age.value;
    height=form.height.value;
    weight=form.weight.value;
    rmr=((5.0033*height)+(13.751*weight)-(age*6.755)+66.473);
    form.RMR.value=rmr;
    }
    // done hiding from old browsers -->
    </script>
    
    </head>
    <body>
    
    <form action="#">
    <h2>RMR Calculator</h2>
    <p>
    Enter Weight, Height, and Age:
    <input name="height" value="0" maxlength="15"  size="15">
    </p><p>
    <input name="weight" value="0" maxlength="15"  size="15">
    </p><p>
    <input name="age" value="0" maxlength="15"  size="15">
    </p><p>
    Click this button to calculate RMR:
    <input name="rmrcalc" value="Calculate" TYPE=BUTTON onclick="computeform(this.form)">
    Your RMR is:
    <input name="RMR" readonly="readonly"  size="15">
    </p>
    </form>
    
    </body>
    </html>
    coothead

  • #4
    New to the CF scene
    Join Date
    Dec 2007
    Posts
    6
    Thanks
    2
    Thanked 0 Times in 0 Posts
    hey thanks for your help guys, coothead your code worked perfectly for me, thanks a lot a really appreciate the help, and thanks for the comments about inches and pounds.
    I was wondering is there a way I could all people to pick whether they are male or female in the script then depending on their sex i could change the formula to compute their RMR or will I just have to have two seperate forms, 1 or males and 1 for females. thanks a lot

  • #5
    Senior Coder coothead's Avatar
    Join Date
    Jan 2004
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    1,680
    Thanks
    0
    Thanked 230 Times in 225 Posts
    Hi there nattauhi,

    these modifications - (highlighted) - will allow you to set a gender value...
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
       "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    
    <script type="text/javascript">
    <!-- hide this script from old browsers
    function computeform(form) {
    if(document.forms[0][0].checked==true) {
       gender=document.forms[0][0].value;
     }
    else{
       gender=document.forms[0][1].value;
     }
    
       age=form.age.value;
       height=form.height.value;
       weight=form.weight.value;
       rmr=((5.0033*height)+(13.751*weight)-(age*6.755)+66.473);
       form.RMR.value=rmr;
     }
    // done hiding from old browsers -->
    </script>
    
    </head>
    <body>
    
    <form action="#">
    <h2>RMR Calculator</h2>
    <p>
    Select gender - 
    male:<input type="radio" name="gender" value="1.6" >
     female:<input type="radio" name="gender" value="1.2" checked="checked">
    </p><p>
    Enter Weight, Height, and Age:
    </p><p>
    <input name="height" value="0" maxlength="15"  size="15">
    </p><p>
    <input name="weight" value="0" maxlength="15"  size="15">
    </p><p>
    <input name="age" value="0" maxlength="15"  size="15">
    </p><p>
    Click this button to calculate RMR:
    <input name="rmrcalc" value="Calculate" type="button" onclick="computeform(this.form)">
    Your RMR is:
    <input name="RMR" readonly="readonly"  size="15">
    </p>
    </form>
    
    </body>
    </html>
    Just change the radio values to suit your requirements.

    coothead
    Last edited by coothead; 01-02-2008 at 09:53 AM.

  • #6
    New to the CF scene
    Join Date
    Dec 2007
    Posts
    6
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Hi coothead, what I want is for the script to use two different formulas if they select male or female. RMR for a male uses this formula: ((5.0033*height)+(13.751*weight)-(age*6.755)+66.473),
    but for a female uses this formula: ((1.8496*height)+(9.463*weight)-(age*4.6756)+655.0955).
    So for if they select male I would want it to use the first formula to calculate their RMR, and if they select female it would need to use the second formula to calculate their RMR.

    Also just wondering what do the radio values effect, I was messing with the script trying to figure these two things out and couldn't figure out what the radio values change.

    And thank you so much for all your help, I'm a little embarrassed to keep asking you questions because you already helped me out so much, I know I wouldn't have been able to figure any of this out without your help, so really, thank you. I greatly appreciate it.

  • #7
    Senior Coder coothead's Avatar
    Join Date
    Jan 2004
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    1,680
    Thanks
    0
    Thanked 230 Times in 225 Posts
    Hi there nattauhi,

    try this it will now work for either gender...
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
       "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    
    <script type="text/javascript">
    <!-- hide this script from old browsers
    function computeform(form) {
    
       age=form.age.value;
       height=form.height.value;
       weight=form.weight.value;
    
    if(document.forms[0][0].checked==true) {
       rmr=((5.0033*height)+(13.751*weight)-(age*6.755)+66.473);
     }
    else {
       rmr=((1.8496*height)+(9.463*weight)-(age*4.6756)+655.0955);
     }
       form.RMR.value=rmr;
     }
    // done hiding from old browsers -->
    </script>
    
    </head>
    <body>
    
    <form action="#">
    <h2>RMR Calculator</h2>
    <p>
    Select gender - 
    male:<input type="radio" name="gender">
     female:<input type="radio" name="gender" checked="checked">
    </p><p>
    Enter Weight, Height, and Age:
    </p><p>
    <input name="height" value="0" maxlength="15"  size="15">
    </p><p>
    <input name="weight" value="0" maxlength="15"  size="15">
    </p><p>
    <input name="age" value="0" maxlength="15"  size="15">
    </p><p>
    Click this button to calculate RMR:
    <input name="rmrcalc" value="Calculate" type="button" onclick="computeform(this.form)">
    Your RMR is:
    <input name="RMR" readonly="readonly"  size="15">
    </p>
    </form>
    
    </body>
    </html>
    Also just wondering what do the radio values effect,
    I only put those in as I did not know what you actually required.
    It is now obvious that values were not required.

    coothead

  • #8
    New to the CF scene
    Join Date
    Dec 2007
    Posts
    6
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Once again thank you coothead, I wouldn't have been able to do figure it out without you. Thanks a bunch.

  • #9
    Senior Coder coothead's Avatar
    Join Date
    Jan 2004
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    1,680
    Thanks
    0
    Thanked 230 Times in 225 Posts
    No problem, you're welcome.

  • Users who have thanked coothead for this post:

    nattauhi (02-08-2008)

  • #10
    New to the CF scene
    Join Date
    Dec 2007
    Posts
    6
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Hey I was wondering if it is possible to have two javascripts on the same page, because I tried putting two scripts on and they dont work, I was messing around with it and just couldnt figure out what to do. Here are my two codes:

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

    <script type="text/javascript">
    <!-- hide this script from old browsers
    function computeform(form) {

    age=form.age.value;
    height=form.height.value;
    weight=form.weight.value;

    if(document.forms[0][0].checked==true) {
    rmr=((5.0033*(height*2.54))+(13.751*(weight/2.2))-(age*6.755)+66.473);
    }
    else {
    rmr=((1.8496*(height*2.54))+(9.463*(weight/2.2))-(age*4.6756)+655.0955);
    }
    form.RMR.value=rmr;
    }
    // done hiding from old browsers -->
    </script>

    </head>
    <body>

    <form action="#">
    <h2>RMR Calculator</h2>
    Select Gender -
    <div>
    Male:<input type="radio" name="gender">
    Female:<input type="radio" name="gender" checked="checked">
    </p><p>
    Enter Height (inches): <input name="height" value="0" maxlength="15" size="15">
    Enter Weight (lbs): <input name="weight" value="0" maxlength="15" size="15">
    Enter Age: <input name="age" value="0" maxlength="15" size="15">
    </p><p>
    Calculate RMR:</b><br>
    <input name="rmrcalc" value="Calculate" type="button" onclick="computeform(this.form)">
    <p>
    Your RMR is:
    <input name="RMR" readonly="readonly" size="15">
    </p>
    </form>

    </body>
    </html>


    the other is

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

    <script type="text/javascript">
    <!-- hide this script from old browsers
    function computeform(form) {

    height=form.height.value;
    weight=form.weight.value;

    if(document.forms[0][0].checked==true) {
    lbm=(((1.082*height)-(4.15*weight))+98.42);
    }
    else {
    lbm=(((1.082*height)-(4.15*weight))+76.76);
    }
    form.LBM.value=lbm;
    }
    // done hiding from old browsers -->
    </script>

    </head>
    <body>

    <form action="#">
    <h2>LBM Calculator</h2>
    Select Gender -
    <div>
    Male:<input type="radio" name="gender">
    Female:<input type="radio" name="gender" checked="checked">
    </p><p>
    Enter Weight (lbs): <input name="height" value="0" maxlength="15" size="15">
    Enter Waist (inches): <input name="weight" value="0" maxlength="15" size="15">
    </p><p>
    Calculate LBM:</b><br>
    <input name="lbmcalc" value="Calculate" type="button" onclick="computeform(this.form)">
    <p>
    Your LBM is:
    <input name="LBM" readonly="readonly" size="15">
    </p>
    </form>

    </body>
    </html>


    Any suggestions would be great. Thanks.

  • #11
    Senior Coder coothead's Avatar
    Join Date
    Jan 2004
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    1,680
    Thanks
    0
    Thanked 230 Times in 225 Posts
    Hi there nattauhi,

    try it like this...
    Code:
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    
    <script type="text/javascript">
    <!-- hide this script from old browsers
    function computeform(form,test) {
    
       age=form.age.value;
       height=form.height.value;
       rmrweight=form.rmrweight.value;
    
       lbmweight=form.lbmweight.value;
       waist=form.waist.value;
    
    if(document.forms[0][0].checked==true) {
       rmr=((5.0033*(height*2.54))+(13.751*(rmrweight/2.2))-(age*6.755)+66.473);
     }
    else {
       rmr=((1.8496*(height*2.54))+(9.463*(rmrweight/2.2))-(age*4.6756)+655.0955);
     }
    
    if(document.forms[0][7].checked==true) {
       lbm=(((1.082*lbmweight)-(4.15*waist))+98.42);
     }
    else {
       lbm=(((1.082*lbmweight)-(4.15*waist))+76.76);
     }
    
    if(test=='rmr') {
       form.RMR.value=rmr.toFixed(3);
     }
    if(test=='lbm') {
       form.LBM.value=lbm.toFixed(3);
      }
     }
    // done hiding from old browsers -->
    </script>
    
    </head>
    <body>
    
    <form action="#">
    <h2>RMR Calculator</h2>
    <p>
    Select Gender -<br>
    Male:<input type="radio" name="rmrgender">
    Female:<input type="radio" name="rmrgender" checked="checked">
    </p><p>
    Enter Height (inches): <input name="height" value="0" maxlength="15" size="15">
    Enter Weight (lbs): <input name="rmrweight" value="0" maxlength="15" size="15">
    Enter Age: <input name="age" value="0" maxlength="15" size="15">
    </p><p>
    Calculate RMR:<br>
    <input name="rmrcalc" value="Calculate" type="button" onclick="computeform(this.form,'rmr')">
    <p>
    Your RMR is:
    <input name="RMR" readonly="readonly" size="15">
    </p>
    
    <h2>LBM Calculator</h2>
    <p>
    Select Gender -<br>
    Male:<input type="radio" name="gender">
    Female:<input type="radio" name="gender" checked="checked">
    </p><p>
    Enter Weight (lbs): <input name="lbmweight" value="0" maxlength="15" size="15">
    Enter Waist (inches): <input name="waist" value="0" maxlength="15" size="15">
    </p><p>
    Calculate LBM:<br>
    <input name="lbmcalc" value="Calculate" type="button" onclick="computeform(this.form,'lbm')">
    </p><p>
    Your LBM is:
    <input name="LBM" readonly="readonly" size="15">
    </p>
    </form>
    
    </body>
    </html>
    
    coothead

  • Users who have thanked coothead for this post:

    nattauhi (02-08-2008)

  • #12
    New to the CF scene
    Join Date
    Dec 2007
    Posts
    6
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Dude Coothead! You're awesome man, seriously a huge thanks.

  • #13
    Senior Coder coothead's Avatar
    Join Date
    Jan 2004
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    1,680
    Thanks
    0
    Thanked 230 Times in 225 Posts
    No problem, you're very 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
    •