Hello Friends Today, through this tutorial, I will tell you How to Write Program kWh to watts calculator using PHP with HTML. To create a kWh to watts calculator using JavaScript with HTML, you can follow the example below. This example allows users to input a value in kilowatt-hours (kWh) and converts it to watts.
INDEX.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>kWh to Watts Calculator</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
}
label {
display: block;
margin-bottom: 8px;
}
input {
width: 100%;
padding: 8px;
margin-bottom: 16px;
box-sizing: border-box;
}
button {
background-color: #4CAF50;
color: white;
padding: 10px 15px;
border: none;
border-radius: 4px;
cursor: pointer;
}
button:hover {
background-color: #45a049;
}
</style>
</head>
<body>
<h2>kWh to Watts Calculator</h2>
<label for="kwh">Enter Energy in kWh:</label>
<input type="number" id="kwh" placeholder="Enter energy in kWh">
<button onclick="convertToWatts()">Convert to Watts</button>
<p id="result"></p>
<script>
function convertToWatts() {
// Get the kWh input value
const kWh = parseFloat(document.getElementById('kwh').value);
// 1 kWh = 1000 watts
const watts = kWh * 1000;
// Display the result
document.getElementById('result').innerHTML = `Energy in Watts: ${watts} watts`;
}
</script>
</body>
</html>
In this HTML file, there’s an input field for entering energy in kWh, a button to trigger the conversion, and a paragraph to display the result in watts. When the button is clicked, the `convertToWatts` JavaScript function is called, which performs the conversion and updates the result on the page.