/    Sign up×
Community /Pin to ProfileBookmark

Hi, I need some help. I am after a BMI program code for both metric and
imperial with a nice simple good looking UI. I want this for a new business
i am looking to start and was wondering if someone in the community could help. I
have no qualms in paying for this to be produced. I know i can get lots of
free ones but all these have an address and link.

to post a comment
Full-stack Developer

14 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJan 13.2017 — BMI == Body Mass Index?
Copy linkTweet thisAlerts:
@stavrossauthorJan 13.2017 — BMI == Body Mass Index?[/QUOTE]

Apologies but yes. BMI = Body Mass Index
Copy linkTweet thisAlerts:
@NogDogJan 14.2017 — My JavaScript skills are pretty atrophied these days, but this seems to work, and could potentially lead you in the right direction:
[code=html]
<html>
<head>
<title>BMI</title>
<style type="text/css">
#bmi_forms {
overflow: auto;
}
#bmi_forms form {
float: left;
}
</style>
<script type="text/javascript">
function calculate(units)
{
var height = 0;
var weight = 0;
if(units == 'imperial') {
height = document.getElementById('imp_height').value;
weight = document.getElementById('imp_weight').value;
height = height * 0.0254;
weight = weight * 0.454;
}
else {
height = document.getElementById('height').value;
weight = document.getElementById('weight').value;
}
var bmi = weight / (height * height);
document.getElementById('bmi').innerHTML = bmi.toFixed(1).toString();
return false;
}
</script>
</head>
<h1>Body Mass Index (BMI) Calculator</h1>
<body>
<div id="bmi_forms">
<form action="" method="post" onsubmit="return calculate('metric')">
<fieldset>
<legend>Calculate BMI: Metric</legend>
<p><label for="weight">Weight (kg): </label><input type="text" name="weight" id="weight" /></p>
<p><label for="height">Height (m): </label><input type="text" name="height" id="height" /></p>
<p><button>Calculate BMI</button></p>
</fieldset>
</form>
<form action="" method="post" onsubmit="return calculate('imperial')">
<fieldset>
<legend>Calculate BMI: Imperial</legend>
<p><label for="weight">Weight (lb): </label><input type="text" name="weight" id="imp_weight" /></p>
<p><label for="height">Height (in): </label><input type="text" name="height" id="imp_height" /></p>
<p><button>Calculate BMI</button></p>
</fieldset>
</form>
</div>
<p>BMI: <span id="bmi"></span></p>
</body>
</html>
[/code]
Copy linkTweet thisAlerts:
@evoluerJan 15.2017 — Hi stavross,

Can i know the full project requirement?. eg: will this be integrated in any other system, will this be a static html page, do you need this in any particular language?. any particular color schemes for the ui?

I suggest you try the above code by nogdog, it works fine with a basic. If you need additional help, please do post it here
Copy linkTweet thisAlerts:
@stavrossauthorJan 16.2017 — Hi stavross,

Can i know the full project requirement?. eg: will this be integrated in any other system, will this be a static html page, do you need this in any particular language?. any particular color schemes for the ui?

I suggest you try the above code by nogdog, it works fine with a basic. If you need additional help, please do post it here[/QUOTE]



Hi Evoluer.

First of all, thanks to nogdog. The code is basic and works well and would be a good starting point.

I need it for a website I am having built and require a natty fresh modern looking BMI calculator, preferably in shades of orange or blue with a font like century gothic and the ability to:

Input age

Choose sex - either M or F

Choose how to input - either metric or imperial

Metric input to take either cm or meters and cm

Imperial to take either feet and inch or just inch. Convert imperial to metric for calculations.

Conclusion to state either: ;You are;

Female

underweight (>=18.5), normal weight(average>=19 <=24), overweight (>25 <30), obese (>=31 <40), seriously obese >40

Male

underweight (>=20), normal weight(average>=20 <=25), overweight (>25 <30), obese (>=31 <40), seriously obese >40

By language, i presume you mean programming language. That's entirely up to you as long as i can integrate to my web page.



I know this sounds a lot to ask for.
Copy linkTweet thisAlerts:
@Kevin2Jan 16.2017 — Modifying NogDog's code to include most of your requirements and to apply some DRY:

[code=html]<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>BMI</title>
<style>
body { font-family: 'Century Gothic', sans-serif; }

fieldset {
border: 0;
margin-top: 1em;
line-height: 1.75em;
}

legend {
margin-left: -1em;
font-weight: bold;
}

#results {display: none;}

input[name=units] { margin-left: 1.5em; }

input[type=number] { width: 3em; }

.u:after {
content: 'Underweight';
background-color: yellow;
}

.n:after {
content: 'Normal';
background-color: green;
color: #fff;
}

.ow:after {
content: 'Overweight';
background-color: yellow;
}

.o:after {
content: 'Obese';
background-color: orange;
}

.so:after {
content: 'Seriously Obese';
background-color: red;
}

#metric:checked ~ #inputs legend:after { content: 'Metric'; }
#metric:checked ~ #inputs label[for=weight]:after { content: '(kg):'; }
#metric:checked ~ #inputs label[for=height]:after { content: '(m):'; }

#imperial:checked ~ #inputs legend:after { content: 'Imperial'; }
#imperial:checked ~ #inputs label[for=weight]:after { content: '(lb):'; }
#imperial:checked ~ #inputs label[for=height]:after { content: '(in):'; }
</style>
<script>
function calculate() {
var height = document.getElementById('height').value,
weight = document.getElementById('weight').value,
bt = document.getElementById('body-type');
if (document.getElementById('imperial').checked == true) {
height = height * 0.0254;
weight = weight * 0.454;
}
var bmi = weight / (height * height);
if (document.getElementById('male').checked == true) {
if (bmi <= 20) {bt.className = 'u';}
else if ((bmi > 20) && (bmi <= 25)) {bt.className = 'n';}
else if ((bmi > 25) && (bmi <= 30)) {bt.className = 'ow';}
else if ((bmi > 30) && (bmi <= 40)) {bt.className = 'o';}
else {bt.className = 'so';}
}
if (document.getElementById('female').checked == true) {
if (bmi <= 18.5) {bt.className = 'u';}
else if ((bmi > 18.5) && (bmi <= 24)) {bt.className = 'n';}
else if ((bmi > 24) && (bmi <= 30)) {bt.className = 'ow';}
else if ((bmi > 30) && (bmi <= 40)) {bt.className = 'o';}
else {bt.className = 'so';}
}
document.getElementById('bmi').innerHTML = bmi.toFixed(1).toString();
document.getElementById('results').style.display = 'block';
return false;
}
</script>
</head>
<body>
<h1>Body Mass Index (BMI) Calculator</h1>

<form action="javascript:;" method="post" onsubmit="return calculate()">
<b>Choose Measuring Units:</b><br>
<input type="radio" name="units" id="metric" checked> <label for="metric">Metric</label><br>
<input type="radio" name="units" id="imperial"> <label for="imperial">Imperial</label>

<fieldset>
<legend>Your gender:</legend>
<label><input type="radio" name="gender" id="male" required> Male</label><br>
<label><input type="radio" name="gender" id="female" required> Female</label>
</fieldset>

<fieldset id="inputs">
<legend>Calculate BMI: </legend>
<label for="weight">Weight </label> <input type="number" name="weight" id="weight" step="any" required><br>
<label for="height">Height </label> <input type="number" name="height" id="height" step="any" required><br>
<button>Calculate BMI</button>
</fieldset>
</form>
<h2>Results:</h2>
<div id="results">
<p>BMI: <span id="bmi"></span></p>
<p>You are: <span id="body-type"></span></p>
</div>
</body>
</html>[/code]


Add in your preferred colors in the styles. To allow feet+inches in the javascript would require a bunch more coding. Easier to use just inches.

And it's good to know I'm "normal" ?.
Copy linkTweet thisAlerts:
@evoluerJan 17.2017 — Hello stavross,

Kevin's code looks good, the only part where you might need changes is in the ui. For that you will need to provide your existing website url so that we can design it according to that layout.
Copy linkTweet thisAlerts:
@stavrossauthorJan 17.2017 — Hi Kevin, Many thanks for the coding you did. Works a treat.
Copy linkTweet thisAlerts:
@stavrossauthorJan 17.2017 — Hi evolver,

My test website url is http://www.nutri-balance.org.uk/. Theres a link on there that will take take you my 'under construction' site.

Anything you can do with the UI would be great, especially if you could make it circa 75mm x 100mm with text side by side.

I know am pushing it a little but could a graph be incorporated to show ranges as bands and the calculated BMI plotted against it?

Once again thanks to everyone on here :-)
Copy linkTweet thisAlerts:
@stavrossauthorJan 19.2017 — Hello stavross,

Kevin's code looks good, the only part where you might need changes is in the ui. For that you will need to provide your existing website url so that we can design it according to that layout.[/QUOTE]


Hi evolver,

My test website url is http://www.nutri-balance.org.uk/. Theres a link on there that will take take you my 'under construction' site.

Anything you can do with the UI would be great, especially if you could make it circa 75mm x 100mm with text side by side.

I know am pushing it a little but could a graph be incorporated to show ranges as bands and the calculated BMI plotted against it?

Once again thanks to everyone on here :-)
Copy linkTweet thisAlerts:
@evoluerJan 21.2017 — Hello stavross,

I had a look at your site, and clicked on "our new website", but it says "bad url - reference number: J6xsYRXhFErJweSCTI3dCg"
Copy linkTweet thisAlerts:
@stavrossauthorJan 23.2017 — Hello stavross,

I had a look at your site, and clicked on "our new website", but it says "bad url - reference number: J6xsYRXhFErJweSCTI3dCg"[/QUOTE]


Hi Evoluer,

The website http://www.nutri-balance.org.uk is live but my main site hasn't gone live yet and is a link on my developers website. If you like i can send get you the link to that site.

If it can be setup for http://www.nutri-balance.org.uk then i think it should be able to be integrated on my main site when finalised.

Geoff
Copy linkTweet thisAlerts:
@evoluerJan 25.2017 — Hello stavross,

The UI part is probably tougher than the coding part. I will need your inputs before starting it. Can you mail me at *************** to discuss this furthur

[B]**Links removed by Site Staff so it doesn't look like you're spamming us. Please don't post them again.**

Acceptable Use Policy

http://www.webdeveloper.com/aup.html[/B]
×

Success!

Help @stavross spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...