forked from msarkajkesavu/Diabetes-Prediction-using-ML
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scriptBee.js
48 lines (39 loc) · 1.83 KB
/
scriptBee.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const menu = document.querySelector('#mobile-menu')
const menuLinks = document.querySelector('.head_menu')
menu.addEventListener('click', function() {
menu.classList.toggle('is-active')
menuLinks.classList.toggle('active')
})
function calculateAge() {
var dob = document.getElementById("date-of-birth").value;
var today = new Date();
var birthDate = new Date(dob);
var age = today.getFullYear() - birthDate.getFullYear();
// Adjust for different month/day combinations
var m = today.getMonth() - birthDate.getMonth();
if (m < 0 || (m === 0 && today.getDate() < birthDate.getDate())) {
age--;
}
document.getElementById("age").value = age;
}
function calculateBMI() {
const weight = parseFloat(document.getElementById("weightInput").value);
const heightInCm = parseFloat(document.getElementById("heightInput").value);
if ((!isNaN(weight) && weight > 0) && (!isNaN(heightInCm) && heightInCm > 0)) {
// Convert height from cm to meters
const heightInM = heightInCm / 100;
const bmi = weight / (heightInM * heightInM);
document.getElementById("bmiInput").value = bmi.toFixed(2);
} else {
document.getElementById("bmiInput").value = ""; // Clear BMI if invalid input
}
}
// Attach input event listeners to recalculate BMI on input change
document.getElementById("weightInput").addEventListener("input", calculateBMI);
document.getElementById("heightInput").addEventListener("input", calculateBMI);
// Optionally, you can trigger the calculation when the page loads
document.addEventListener("DOMContentLoaded", calculateBMI);
// Display the current value of the slider
document.getElementById("HbA1c_level").addEventListener("input", function() {
document.getElementById("sliderValue").innerText = this.value;
});