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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    BMI Calculator - Novice cannot get it working!

    Hello

    I have been asked by a friend to put together a BMI calculator. I know there are javascript ones already out there that I could use the code for, but

    a) it needs to do a specific thing
    b) I am interested in learning a bit of jscript - hence why I just spent about 4hrs trying to get it working

    You can see what I have been working on here

    http://www.kubedp.co.uk/bmi2.html

    Basically - what it needs to do is the following :-
    - User can either enter Feet/Inches or centimeters for height
    - User can either enter Stones/Pounds or Kilos for weight.
    - If they enter Feeet/Inches and centimeters - it throws an error (similar thing for weight).

    It then outputs the BMI to txtBMIResults.

    I managed to get the validation working on not having both Stones/Pounds and Kilos filled in etc, but when it comes to the actual calculation - I am stumped.

    If someone could look at this for me and hopefully code it and comment it so I can understand what has been done to get it working so I might learn, that would be fantastic.

    http://www.bmi-calculator.net/bmi-formula.php

    Is the formulas for calculating BMI.

    Not sure if you can tell from the code - but I was trying to get it so that the calculation was always done on Kilos and Meters, so I was taking the Stones and Pounds and feet and inches and trying to convert it to kilos and metres and then run the calculation.

    Hope I have been clear.

    Many thanks for any help anyone can offer

  • #2
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,981
    Thanks
    56
    Thanked 557 Times in 554 Posts
    you need to look at your code using an error console. I like the firebug plug in for firefox, others prefer the built-in one in Chrome.

    Anyway. The first error that pops is:

    invalid assignment left-hand side
    document.form.txtWeight_Kilos.value = "" &&

    in javascript = assigns a value to a variable and == compares two variables. You can have a look here and here for more info

  • #3
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hurrah!

    Thank you for that. I have installed Firebug now - sure it will come in handy!.

    Using your tip about the == I have managed to get it working.

    http://www.kubedp.co.uk/BMICalculator.html

    I know to most avid scripters this will be a nothing script - but I feel like I have accomplished something by getting this working.

    Thank you again for your help.


  •  

    Posting Permissions

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