Last active
December 11, 2015 19:28
-
-
Save Yves-T/4648472 to your computer and use it in GitHub Desktop.
DOJO: BMI calculation with number spinners
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Calculate BMI</title> | |
<script src="//ajax.googleapis.com/ajax/libs/dojo/1.8.3/dojo/dojo.js"></script> | |
<script src="scripts/bmi.js"></script> | |
<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/dojo/1.8.1/dijit/themes/claro/claro.css"> | |
<style> | |
#answer { | |
display: inline; | |
} | |
</style> | |
</head> | |
<body class="claro"> | |
<p>Massa in kg: </p> | |
<div id="massaSpinnerId"></div> | |
<p>Lengte in cm: </p> | |
<div id="lengteSpinnerId"></div> | |
<h3>BMI:</h3> | |
<span>BMI: | |
<p id="answer"></p></span> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require(["dojo/dom", "dojo/domReady!"], function (dom) { | |
function calculateBMI() { | |
var answer = dom.byId("answer"); | |
// calculate bmi | |
answer.innerHTML = roundNumber((massaSpinner.getValue() / Math.pow(lemgteSpinner.getValue() / 100, 2)), 1); | |
} | |
function roundNumber(number, digits) { | |
var multiple = Math.pow(10, digits); | |
return Math.round(number * multiple) / multiple; | |
} | |
var massaSpinner; | |
var lemgteSpinner; | |
require(["dijit/form/NumberSpinner"], function (NumberSpinner) { | |
massaSpinner = new NumberSpinner({ | |
value:60, | |
smallDelta:1, | |
constraints:{ min:9, max:120, places:0 }, | |
id:"integerspinner3", | |
style:"width:100px", | |
intermediateChanges:true, | |
onClick:calculateBMI, | |
onChange:calculateBMI | |
}, "massaSpinnerId"); | |
//massaSpinner.startup(); | |
lemgteSpinner = new NumberSpinner({ | |
value:170, | |
smallDelta:1, | |
constraints:{ min:60, max:220, places:0 }, | |
id:"integerspinner4", | |
style:"width:100px", | |
intermediateChanges:true, | |
onClick:calculateBMI, | |
onChange:calculateBMI | |
}, "lengteSpinnerId"); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment