content logo

Bootstrap Forms:

Bootstrap Online Health Computer Form

You probably have seen health websites with different designs. In this post, we have included a code that shows you a great health form. This code is the Bootstrap Online Health Computer Form with a great performance. The Bootstrap Health Form is so functional and you can use it if you have a Pagan Nutrition website. By using this HTML Health Form, you can engage your users and attract more visitors. So, look at this post and use the following code carefully.

In this preview, you can realize the beauty of its background. The following Javascript Form Code has a white and pink background with a large border. There are many fields on this page with a white background. After filling in all blanks, you should click on “Start Calculate” with a black background and white text. Then, you can see the amount of calorie that you have to receive. If you don’t fill in all blanks and enter the button, you will face an error with red color which means you should fill in all blanks. At the bottom of the page, there are three sections related to BMI, BMR, and TDEE. These elements of the Simple Health Computer Code are separated with some black lines.

 

#

Bootstrap Health Form

#

HTML Health Form

#

Javascript Form Code

#

Simple Health Computer Code

<!-- This script got from frontendfreecode.com -->
<h1 class="title">health computer</h1>
<div class="main">
    <form class="form">
        <div class="mb-3 row">
            <label for="gender" class="col-3 col-form-label">Gender</label>
            <div class="col-8">
                <select id="gender" class="form-select">
                    <option value="1">male</option>
                    <option value="2">female</option>
                </select>
            </div>
        </div>
        <div class="mb-3 row">
            <label for="age" class="col-3 col-form-label">Age</label>
            <div class="col-8">
                <input type="number" class="form-control" id="age" />
            </div>
        </div>
        <div class="mb-3 row">
            <label for="height" class="col-3 col-form-label">Height</label>
            <div class="col-8">
                <input type="number" class="form-control" id="height" />
            </div>
        </div>
        <div class="mb-3 row">
            <label for="weight" class="col-3 col-form-label">Weight</label>
            <div class="col-8">
                <input type="number" class="form-control" id="weight" />
            </div>
        </div>
        <div class="mb-3 row">
            <label for="active" class="col-3 col-form-label">Gender</label>
            <div class="col-8">
                <select id="active" class="form-select">
                    <option value="1.2">no exercise</option>
                    <option value="1.375">exercise 1-3 days a week</option>
                    <option value="1.55">exercise 4-5 days a week</option>
                    <option value="1.725">exercise 6-7 days a week</option>
                    <option value="1.9">in motion all the time</option>
                </select>
            </div>
        </div>
        <div class="text-danger mb-3" id="error"></div>
        <button type="button" class="btn btn-dark" id="submit">
            start calculate
        </button>
    </form>
    <div class="result">
        <div class="result_text">
            <p>Body Mass Index(BMI) <span id="bmi"></span></p>
            <hr />
            <p>Basal Metabolic Rate (BMR) <span id="bmr"></span></p>
            <hr />
            <p>Total daily caloric expenditure (TDEE) <span id="tdee"></span></p>
        </div>
    </div>
</div><a style="font-size: 8pt; text-decoration: none" target="_blank" href="http://frontendfreecode.com">Free Frontend</a>
                                                                            
body, html {
	margin: 0;
	padding: 0;
	width: 100%;
	height: 100%;
}
body {
	background-image: linear-gradient(135deg, #fdfcfb 0%, #e2d1c3 100%);
}
.title {
	text-align: center;
	margin: 16px 0;
}
.main {
	display: flex;
}
.form, .result {
	width: 50%;
	border: 1px solid #222;
	border-radius: 8px;
	margin: 0 32px;
	padding: 32px;
}
.form {
	text-align: center;
}
.text-danger {
	height: 30px;
}
.result_text {
	padding: 0 32px;
}
@media screen and (max-width: 768px) {
	.main {
		margin: 0;
		display: block;
	}
	.form, .result {
		width: calc(100% - 32px);
		margin: 0 16px 32px;
		padding: 32px 0;
	}
}
$("#submit").click(function (e) {
    e.preventDefault();
    let ageNum = $("#age").val();
    let weightNum = $("#weight").val();
    let heightNum = $("#height").val();
    let genderNum = $("#gender").val();
    let activeNum = $("#active").val();
    let errorMsg = "";
    let newBmi = 0;
    let newBmiText = "";
    let newBmr = 0;
    let newTdee = 0;
    if (ageNum === "" || ageNum > 100) {
        errorMsg = "Please enter correct age";
    }
    if (heightNum === "" || heightNum > 200 || heightNum < 0) {
        errorMsg = "Please enter correct height";
    }
    if (weightNum === "" || weightNum > 150 || weightNum < 0) {
        errorMsg = "Please enter correct weight";
    }
    function getBmi(heightNum, weightNum) {
        newBmi = weightNum / Math.pow(heightNum / 100, 2);
        newBmi = Math.round(newBmi * 100) / 100;
        return newBmi;
    }
    if (errorMsg === "") {
        if (genderNum === "1") {
            newBmr =
                weightNum * 10 + heightNum * 6.25 + ageNum * 5 + 6;
            getBmi(heightNum, weightNum);
        }
        if (genderNum === "2") {
            newBmr =
                weightNum * 10 +
                heightNum * 6.25 -
                ageNum * 5 -
                161;
            getBmi(heightNum, weightNum);
        }
        if (newBmi < 18.5) {
            newBmiText = "Too light";
        } else if (newBmi < 24 && newBmi >= 18.5) {
            newBmiText = "normal range";
        } else if (newBmi < 27 && newBmi >= 24) {
            newBmiText = "Overweight";
        } else if (newBmi < 30 && newBmi >= 27) {
            newBmiText = "mild obesity";
        } else if (newBmi < 35 && newBmi >= 30) {
            newBmiText = "moderate obesity";
        } else {
            newBmiText = "severe obesity";
        }
        $("#bmi").text(`${newBmi} ,belong ${newBmiText}`);
        newTdee = (Math.round(newBmr * activeNum) * 100) / 100;
        $("#bmr").text(newBmr);
        $("#tdee").text(`${newTdee} kcal`);
    }
    $("#error").text(errorMsg);
});
<link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.0.2/css/bootstrap.min.css'>
<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js'></script>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<!-- This script got from frontendfreecode.com -->

<link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.0.2/css/bootstrap.min.css'>
<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js'></script>
<style>
body, html {
	margin: 0;
	padding: 0;
	width: 100%;
	height: 100%;
}
body {
	background-image: linear-gradient(135deg, #fdfcfb 0%, #e2d1c3 100%);
}
.title {
	text-align: center;
	margin: 16px 0;
}
.main {
	display: flex;
}
.form, .result {
	width: 50%;
	border: 1px solid #222;
	border-radius: 8px;
	margin: 0 32px;
	padding: 32px;
}
.form {
	text-align: center;
}
.text-danger {
	height: 30px;
}
.result_text {
	padding: 0 32px;
}
@media screen and (max-width: 768px) {
	.main {
		margin: 0;
		display: block;
	}
	.form, .result {
		width: calc(100% - 32px);
		margin: 0 16px 32px;
		padding: 32px 0;
	}
}
</style>

</head>
<body>
<h1 class="title">health computer</h1>
<div class="main">
    <form class="form">
        <div class="mb-3 row">
            <label for="gender" class="col-3 col-form-label">Gender</label>
            <div class="col-8">
                <select id="gender" class="form-select">
                    <option value="1">male</option>
                    <option value="2">female</option>
                </select>
            </div>
        </div>
        <div class="mb-3 row">
            <label for="age" class="col-3 col-form-label">Age</label>
            <div class="col-8">
                <input type="number" class="form-control" id="age" />
            </div>
        </div>
        <div class="mb-3 row">
            <label for="height" class="col-3 col-form-label">Height</label>
            <div class="col-8">
                <input type="number" class="form-control" id="height" />
            </div>
        </div>
        <div class="mb-3 row">
            <label for="weight" class="col-3 col-form-label">Weight</label>
            <div class="col-8">
                <input type="number" class="form-control" id="weight" />
            </div>
        </div>
        <div class="mb-3 row">
            <label for="active" class="col-3 col-form-label">Gender</label>
            <div class="col-8">
                <select id="active" class="form-select">
                    <option value="1.2">no exercise</option>
                    <option value="1.375">exercise 1-3 days a week</option>
                    <option value="1.55">exercise 4-5 days a week</option>
                    <option value="1.725">exercise 6-7 days a week</option>
                    <option value="1.9">in motion all the time</option>
                </select>
            </div>
        </div>
        <div class="text-danger mb-3" id="error"></div>
        <button type="button" class="btn btn-dark" id="submit">
            start calculate
        </button>
    </form>
    <div class="result">
        <div class="result_text">
            <p>Body Mass Index(BMI) <span id="bmi"></span></p>
            <hr />
            <p>Basal Metabolic Rate (BMR) <span id="bmr"></span></p>
            <hr />
            <p>Total daily caloric expenditure (TDEE) <span id="tdee"></span></p>
        </div>
    </div>
</div><div id="bcl"><a style="font-size:8pt;text-decoration:none;" href="http://www.devanswer.com">Free Frontend</a></div>
<script>
$("#submit").click(function (e) {
    e.preventDefault();
    let ageNum = $("#age").val();
    let weightNum = $("#weight").val();
    let heightNum = $("#height").val();
    let genderNum = $("#gender").val();
    let activeNum = $("#active").val();
    let errorMsg = "";
    let newBmi = 0;
    let newBmiText = "";
    let newBmr = 0;
    let newTdee = 0;
    if (ageNum === "" || ageNum > 100) {
        errorMsg = "Please enter correct age";
    }
    if (heightNum === "" || heightNum > 200 || heightNum < 0) {
        errorMsg = "Please enter correct height";
    }
    if (weightNum === "" || weightNum > 150 || weightNum < 0) {
        errorMsg = "Please enter correct weight";
    }
    function getBmi(heightNum, weightNum) {
        newBmi = weightNum / Math.pow(heightNum / 100, 2);
        newBmi = Math.round(newBmi * 100) / 100;
        return newBmi;
    }
    if (errorMsg === "") {
        if (genderNum === "1") {
            newBmr =
                weightNum * 10 + heightNum * 6.25 + ageNum * 5 + 6;
            getBmi(heightNum, weightNum);
        }
        if (genderNum === "2") {
            newBmr =
                weightNum * 10 +
                heightNum * 6.25 -
                ageNum * 5 -
                161;
            getBmi(heightNum, weightNum);
        }
        if (newBmi < 18.5) {
            newBmiText = "Too light";
        } else if (newBmi < 24 && newBmi >= 18.5) {
            newBmiText = "normal range";
        } else if (newBmi < 27 && newBmi >= 24) {
            newBmiText = "Overweight";
        } else if (newBmi < 30 && newBmi >= 27) {
            newBmiText = "mild obesity";
        } else if (newBmi < 35 && newBmi >= 30) {
            newBmiText = "moderate obesity";
        } else {
            newBmiText = "severe obesity";
        }
        $("#bmi").text(`${newBmi} ,belong ${newBmiText}`);
        newTdee = (Math.round(newBmr * activeNum) * 100) / 100;
        $("#bmr").text(newBmr);
        $("#tdee").text(`${newTdee} kcal`);
    }
    $("#error").text(errorMsg);
});
</script>

</body>
</html>
Preview