Revision as of 23:55, 7 May 2013 by hamishwillee (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

BMI widget

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Tested with
Devices(s): Nokia N96
Platform(s): S60 3rd FP2,S60 5th Edition
Platform Security
Capabilities: )
Keywords: widget
Created: ck.umraliya (08 Jan 2009)
Last edited: hamishwillee (07 May 2013)



BMI is a simple widget application which takes a person's height and weight and based upon that data it calculates the Body Mass Index of a person. BMI widget shows how we can put different images and text in a view based upon the calculation result we get. The widget package is attached below.

html code

<link rel="StyleSheet" href="BMI.css" type="text/css" />
<script type="text/javascript" src="BMI.js" />
<body bgcolor="#CDCDB4">
<!-- Get data -->
<div id="mainView">
<h2>Your Health</h2>
<p>The Body Mass index is a statistical measurement which compares a person's weight and height.It is useful to measure a healthy body weight based on how tall a person is.</p>
<label for="ht">Enter your height(in cm):</label>
<input class="input" type="text" id="ht" size="4" value=""/>
<label for="wt">Enter your weight(in kg):</label>
<input class="input" type="text" id="wt" size="4" value=""/>
<input class="button" type="button" name="calc" value="CALCULATE" onClick="showResult();" />
<!-- Show Result -->
<div id="resultView">
<h2>Your Health</h2>
<U>BMI categories</U>
<p> BMI < 18.5 : UnderWeight</p>
BMI = 18.5-24.9 : Normal Weight
<p> BMI = 25-29.9  : Over Weight</p>
<p>BMI > 30 : Obesity</p>
<p id="output1"></p>
<p id="output2"></p>
<img id="sign" src="" />
<p id="output3"></p>


Following is the part of javascript file which calculates the BMI:

function calculate()
{ //Get height and Weight of user
URheight = document.getElementById("ht").value;
URweight = document.getElementById("wt").value;
//Calculate BMI
BMI = (10000*URweight)/(URheight*URheight);
//Assign image and text according to BMI
if (BMI < 18.50) {
var imgSrc = 'img/uw.png';
return [BMI, word[1], imgSrc]
if (BMI > 18.50 && BMI < 25) {
var imgSrc = 'img/ft.png';
return [BMI, word[0], imgSrc]
if (BMI > 25 && BMI < 30) {
var imgSrc = 'img/ow.png';
return [BMI, word[2], imgSrc]
if (BMI > 30) {
var imgSrc = 'img/ob.png';
return [BMI, word[3], imgSrc]



Widget download

Rename the file to BMI.wgz before installation. BMI.zip

This page was last modified on 7 May 2013, at 23:55.
85 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.


Thank you!

We appreciate your feedback.