Power Factor Calculator Using JavaScript HTML With Example

Hello Friends Today, through this tutorial, I will tell you How to Write Program Power Factor calculator using PHP with HTML? Sure! Below is a simple example of a power factor calculator using JavaScript and HTML:

index.html

<!DOCTYPE html>
<html>
<head>
<title>Power Factor Calculator</title>
<script>
function calculatePowerFactor() {
var realPower = parseFloat(document.getElementById("realPower").value);
var apparentPower = parseFloat(document.getElementById("apparentPower").value);

if (isNaN(realPower) || isNaN(apparentPower)) {
document.getElementById("powerFactorResult").innerHTML = "Please enter valid numbers.";
return;
}

var powerFactor = realPower / apparentPower;
document.getElementById("powerFactorResult").innerHTML = "Power Factor: " + powerFactor.toFixed(2);
}
</script>
</head>
<body>
<h1>Power Factor Calculator</h1>
<label for="realPower">Real Power (W):</label>
<input type="number" id="realPower"><br><br>
<label for="apparentPower">Apparent Power (VA):</label>
<input type="number" id="apparentPower"><br><br>

<button onclick="calculatePowerFactor()">Calculate Power Factor</button><br><br>
<div id="powerFactorResult"></div>
</body>
</html>

This code creates a simple HTML page with two input fields for real power and apparent power, and a button to calculate the power factor. When the button is clicked, the `calculatePowerFactor()` JavaScript function is called, which calculates the power factor using the provided values and displays the result below the button.

Example:-

Power Factor Calculator