Last active
June 13, 2018 03:55
-
-
Save AminBusiness/2fbd5aaee80aabfd456670e8499cf9f8 to your computer and use it in GitHub Desktop.
// source https://jsbin.com
This file contains 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> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
// Declare and initialize global constants | |
const MINHEIGHT = 12; // Minimum allowable height | |
const MAXHEIGHT = 96; // Maximum allowable height | |
const MINWEIGHT = 1; // Minimum allowable weight | |
const MAXWEIGHT = 555; // Maximum allowable weight | |
const MINOPT = 18.5; // Minimum optimal weight | |
const MAXOPT = 25.0; // Maximum optimal weight | |
// Declare global variable | |
var img; | |
var hFlag = true; // valid height flag | |
var wFlag = true; // valid weight flag | |
var bmi = 0.0; // Body mass index | |
var height = (document.getElementById("height").value).trim(); | |
var weight = (document.getElementById("weight").value).trim(); | |
function calcHeight() | |
{ | |
if (height === "") | |
{ | |
heightError.innerHTML = "Height must be a number between " + | |
MINHEIGHT + " and " + MAXHEIGHT + " inches!"; | |
document.form1.height.value = ""; | |
hFlag = false; | |
} | |
else if ((height < MINHEIGHT) || (height > MAXHEIGHT)) | |
{ | |
heightError.innerHTML = "Height must be between " + | |
MINHEIGHT + " and " + MAXHEIGHT + " inches!"; | |
document.form1.height.value = ""; | |
hFlag = false; | |
} | |
else | |
{ | |
heightError.innerHTML = ""; | |
hFlag = true; | |
} | |
} | |
function calcWeight() | |
{ | |
if (weight === "") | |
{ | |
weightError.innerHTML = "Weight must be a number between " + | |
MINWEIGHT + " and " + MAXWEIGHT + " pounds!"; | |
document.form1.weight.value = ""; | |
wFlag = false; | |
} | |
else if ((weight < MINWEIGHT) || (weight > MAXWEIGHT)) | |
{ | |
weightError.innerHTML = "Weight must be between " + | |
MINWEIGHT + " and " + MAXWEIGHT + " pounds!"; | |
document.form1.weight.value = ""; | |
wFlag = false; | |
} | |
else | |
{ | |
weightError.innerHTML = ""; | |
wFlag = true; | |
} | |
} | |
function calcBMI() | |
{ | |
if ((hFlag === true) && (wFlag === true)) | |
{ | |
bmi = ((weight / (height * height)) * 703).toFixed(2); | |
document.form1.bmi.value = bmi.toString(); | |
setTimeout(function(){ clear(); }, 5000); | |
return true; | |
} | |
else | |
{ | |
clear(); | |
} | |
} | |
function calcStatus() | |
{ | |
if (bmi < MINOPT) | |
{ | |
document.form1.bmiStatus.value = "UNDERWEIGHT"; | |
setPicture("under"); | |
} | |
else if (bmi > MAXOPT) | |
{ | |
document.form1.bmiStatus.value = "OVERWEIGHT"; | |
setPicture("over"); | |
} | |
else | |
{ | |
document.form1.bmiStatus.value = "OPTIMAL WEIGHT"; | |
setPicture("fit"); | |
} | |
} | |
function setPicture(elem) | |
{ | |
var theSrc = "images/" + elem + ".jpg"; | |
img = document.createElement("img"); | |
img.setAttribute("src", theSrc); | |
//alert ("The value of the src attribute is: " + theSrc); | |
img.setAttribute("height", "250"); | |
img.setAttribute("width", "250"); | |
img.setAttribute("alt", "BMI image"); | |
img.setAttribute("id", "pic"); | |
document.getElementById("picture").appendChild(img); | |
} | |
function clear() | |
{ | |
document.form1.height.value = ""; | |
document.form1.weight.value = ""; | |
document.form1.bmi.value = ""; | |
document.form1.bmiStatus.value = ""; | |
document.form1.heightError.innerHTML = ""; | |
document.form1.weightError.innerHTML = ""; | |
//document.getElementById("picture").style.display = "none"; | |
document.getElementById("picture").removeChild(img); | |
return false; | |
} | |
if (submit.addEventListener) | |
{ | |
submit.addEventListener("click", calculate, false); | |
} | |
else if (submit.attachEvent) | |
{ | |
submit.attachEvent("onclick", calculate); | |
} | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">// Declare and initialize global constants | |
const MINHEIGHT = 12; // Minimum allowable height | |
const MAXHEIGHT = 96; // Maximum allowable height | |
const MINWEIGHT = 1; // Minimum allowable weight | |
const MAXWEIGHT = 555; // Maximum allowable weight | |
const MINOPT = 18.5; // Minimum optimal weight | |
const MAXOPT = 25.0; // Maximum optimal weight | |
// Declare global variable | |
var img; | |
var hFlag = true; // valid height flag | |
var wFlag = true; // valid weight flag | |
var bmi = 0.0; // Body mass index | |
var height = (document.getElementById("height").value).trim(); | |
var weight = (document.getElementById("weight").value).trim(); | |
function calcHeight() | |
{ | |
if (height === "") | |
{ | |
heightError.innerHTML = "Height must be a number between " + | |
MINHEIGHT + " and " + MAXHEIGHT + " inches!"; | |
document.form1.height.value = ""; | |
hFlag = false; | |
} | |
else if ((height < MINHEIGHT) || (height > MAXHEIGHT)) | |
{ | |
heightError.innerHTML = "Height must be between " + | |
MINHEIGHT + " and " + MAXHEIGHT + " inches!"; | |
document.form1.height.value = ""; | |
hFlag = false; | |
} | |
else | |
{ | |
heightError.innerHTML = ""; | |
hFlag = true; | |
} | |
} | |
function calcWeight() | |
{ | |
if (weight === "") | |
{ | |
weightError.innerHTML = "Weight must be a number between " + | |
MINWEIGHT + " and " + MAXWEIGHT + " pounds!"; | |
document.form1.weight.value = ""; | |
wFlag = false; | |
} | |
else if ((weight < MINWEIGHT) || (weight > MAXWEIGHT)) | |
{ | |
weightError.innerHTML = "Weight must be between " + | |
MINWEIGHT + " and " + MAXWEIGHT + " pounds!"; | |
document.form1.weight.value = ""; | |
wFlag = false; | |
} | |
else | |
{ | |
weightError.innerHTML = ""; | |
wFlag = true; | |
} | |
} | |
function calcBMI() | |
{ | |
if ((hFlag === true) && (wFlag === true)) | |
{ | |
bmi = ((weight / (height * height)) * 703).toFixed(2); | |
document.form1.bmi.value = bmi.toString(); | |
setTimeout(function(){ clear(); }, 5000); | |
return true; | |
} | |
else | |
{ | |
clear(); | |
} | |
} | |
function calcStatus() | |
{ | |
if (bmi < MINOPT) | |
{ | |
document.form1.bmiStatus.value = "UNDERWEIGHT"; | |
setPicture("under"); | |
} | |
else if (bmi > MAXOPT) | |
{ | |
document.form1.bmiStatus.value = "OVERWEIGHT"; | |
setPicture("over"); | |
} | |
else | |
{ | |
document.form1.bmiStatus.value = "OPTIMAL WEIGHT"; | |
setPicture("fit"); | |
} | |
} | |
function setPicture(elem) | |
{ | |
var theSrc = "images/" + elem + ".jpg"; | |
img = document.createElement("img"); | |
img.setAttribute("src", theSrc); | |
//alert ("The value of the src attribute is: " + theSrc); | |
img.setAttribute("height", "250"); | |
img.setAttribute("width", "250"); | |
img.setAttribute("alt", "BMI image"); | |
img.setAttribute("id", "pic"); | |
document.getElementById("picture").appendChild(img); | |
} | |
function clear() | |
{ | |
document.form1.height.value = ""; | |
document.form1.weight.value = ""; | |
document.form1.bmi.value = ""; | |
document.form1.bmiStatus.value = ""; | |
document.form1.heightError.innerHTML = ""; | |
document.form1.weightError.innerHTML = ""; | |
//document.getElementById("picture").style.display = "none"; | |
document.getElementById("picture").removeChild(img); | |
return false; | |
} | |
if (submit.addEventListener) | |
{ | |
submit.addEventListener("click", calculate, false); | |
} | |
else if (submit.attachEvent) | |
{ | |
submit.attachEvent("onclick", calculate); | |
} | |
</script></body> | |
</html> |
This file contains 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
// Declare and initialize global constants | |
const MINHEIGHT = 12; // Minimum allowable height | |
const MAXHEIGHT = 96; // Maximum allowable height | |
const MINWEIGHT = 1; // Minimum allowable weight | |
const MAXWEIGHT = 555; // Maximum allowable weight | |
const MINOPT = 18.5; // Minimum optimal weight | |
const MAXOPT = 25.0; // Maximum optimal weight | |
// Declare global variable | |
var img; | |
var hFlag = true; // valid height flag | |
var wFlag = true; // valid weight flag | |
var bmi = 0.0; // Body mass index | |
var height = (document.getElementById("height").value).trim(); | |
var weight = (document.getElementById("weight").value).trim(); | |
function calcHeight() | |
{ | |
if (height === "") | |
{ | |
heightError.innerHTML = "Height must be a number between " + | |
MINHEIGHT + " and " + MAXHEIGHT + " inches!"; | |
document.form1.height.value = ""; | |
hFlag = false; | |
} | |
else if ((height < MINHEIGHT) || (height > MAXHEIGHT)) | |
{ | |
heightError.innerHTML = "Height must be between " + | |
MINHEIGHT + " and " + MAXHEIGHT + " inches!"; | |
document.form1.height.value = ""; | |
hFlag = false; | |
} | |
else | |
{ | |
heightError.innerHTML = ""; | |
hFlag = true; | |
} | |
} | |
function calcWeight() | |
{ | |
if (weight === "") | |
{ | |
weightError.innerHTML = "Weight must be a number between " + | |
MINWEIGHT + " and " + MAXWEIGHT + " pounds!"; | |
document.form1.weight.value = ""; | |
wFlag = false; | |
} | |
else if ((weight < MINWEIGHT) || (weight > MAXWEIGHT)) | |
{ | |
weightError.innerHTML = "Weight must be between " + | |
MINWEIGHT + " and " + MAXWEIGHT + " pounds!"; | |
document.form1.weight.value = ""; | |
wFlag = false; | |
} | |
else | |
{ | |
weightError.innerHTML = ""; | |
wFlag = true; | |
} | |
} | |
function calcBMI() | |
{ | |
if ((hFlag === true) && (wFlag === true)) | |
{ | |
bmi = ((weight / (height * height)) * 703).toFixed(2); | |
document.form1.bmi.value = bmi.toString(); | |
setTimeout(function(){ clear(); }, 5000); | |
return true; | |
} | |
else | |
{ | |
clear(); | |
} | |
} | |
function calcStatus() | |
{ | |
if (bmi < MINOPT) | |
{ | |
document.form1.bmiStatus.value = "UNDERWEIGHT"; | |
setPicture("under"); | |
} | |
else if (bmi > MAXOPT) | |
{ | |
document.form1.bmiStatus.value = "OVERWEIGHT"; | |
setPicture("over"); | |
} | |
else | |
{ | |
document.form1.bmiStatus.value = "OPTIMAL WEIGHT"; | |
setPicture("fit"); | |
} | |
} | |
function setPicture(elem) | |
{ | |
var theSrc = "images/" + elem + ".jpg"; | |
img = document.createElement("img"); | |
img.setAttribute("src", theSrc); | |
//alert ("The value of the src attribute is: " + theSrc); | |
img.setAttribute("height", "250"); | |
img.setAttribute("width", "250"); | |
img.setAttribute("alt", "BMI image"); | |
img.setAttribute("id", "pic"); | |
document.getElementById("picture").appendChild(img); | |
} | |
function clear() | |
{ | |
document.form1.height.value = ""; | |
document.form1.weight.value = ""; | |
document.form1.bmi.value = ""; | |
document.form1.bmiStatus.value = ""; | |
document.form1.heightError.innerHTML = ""; | |
document.form1.weightError.innerHTML = ""; | |
//document.getElementById("picture").style.display = "none"; | |
document.getElementById("picture").removeChild(img); | |
return false; | |
} | |
if (submit.addEventListener) | |
{ | |
submit.addEventListener("click", calculate, false); | |
} | |
else if (submit.attachEvent) | |
{ | |
submit.attachEvent("onclick", calculate); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment