Based on ChatGPT reply https://chat.openai.com/share/991bdeb0-628a-4eed-b267-39f873f38af9
Can calculate any empty textbox.
Based on ChatGPT reply https://chat.openai.com/share/991bdeb0-628a-4eed-b267-39f873f38af9
Can calculate any empty textbox.
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>BMI Calculator</title> | |
</head> | |
<body> | |
<h1>BMI Calculator</h1> | |
<label for="weight">Weight (kg):</label> | |
<input type="text" id="weight" /> | |
<label for="height">Height (cm):</label> | |
<input type="text" id="height" /> | |
<label for="bmi">BMI:</label> | |
<input type="text" id="bmi" /> | |
<input type="button" value="Calculate" onclick="calculateBMI()" /> | |
<script src="script.js"></script> | |
</body> | |
</html> |
// https://chat.openai.com/share/991bdeb0-628a-4eed-b267-39f873f38af9 | |
function calculateBMI() { | |
const weightInput = document.getElementById("weight"); | |
const heightInput = document.getElementById("height"); | |
const bmiInput = document.getElementById("bmi"); | |
let weight = parseFloat(weightInput.value); | |
let height = parseFloat(heightInput.value) / 100; // Convert cm to meters | |
let bmi = parseFloat(bmiInput.value); | |
if (!isNaN(weight) && !isNaN(height)) { | |
bmi = (weight / (height * height)).toFixed(2); | |
bmiInput.value = bmi; | |
} else if (!isNaN(weight) && !isNaN(bmi)) { | |
height = (Math.sqrt(weight / bmi) * 100).toFixed(2); | |
heightInput.value = height; | |
} else if (!isNaN(bmi) && !isNaN(height)) { | |
weight = (bmi * (height * height)).toFixed(2); | |
weightInput.value = weight; | |
} | |
} |
body { | |
font-family: Arial, sans-serif; | |
max-width: 400px; | |
margin: 0 auto; | |
padding: 20px; | |
} | |
h1 { | |
text-align: center; | |
} | |
label { | |
display: block; | |
margin-bottom: 5px; | |
} | |
input { | |
width: 100%; | |
padding: 5px; | |
margin-bottom: 10px; | |
} |