Online Percentage calculator

HTML code of Online Percentage calculator

<!DOCTYPE html>
<html lang=”en”>
<head>
<meta charset=”UTF-8″>
<meta name=”viewport” content=”width=device-width, initial-scale=1.0″>
<title>Percentage Calculator</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
box-sizing: border-box;
}
.container {
max-width: 400px;
margin: 50px auto;
padding: 20px;
border: 1px solid #ccc;
border-radius: 5px;
background-color: #f9f9f9;
}
.form-group {
margin-bottom: 15px;
}
label {
display: block;
margin-bottom: 5px;
}
input[type=”number”] {
width: 100%;
padding: 8px;
border: 1px solid #ccc;
border-radius: 3px;
}
button {
background-color: #4CAF50;
color: white;
padding: 10px 20px;
border: none;
border-radius: 3px;
cursor: pointer;
}
button:hover {
background-color: #45a049;
}
</style>
</head>
<body>
<div class=”container”>
<h2>Percentage Calculator</h2>
<div class=”form-group”>
<label for=”total”>Total:</label>
<input type=”number” id=”total” placeholder=”Enter total value”>
</div>
<div class=”form-group”>
<label for=”percentage”>Percentage:</label>
<input type=”number” id=”percentage” placeholder=”Enter percentage value”>
</div>
<button onclick=”calculatePercentage()”>Calculate</button>
<div class=”form-group”>
<label for=”result”>Result:</label>
<input type=”text” id=”result” readonly>
</div>
</div>

<script>
function calculatePercentage() {
var total = parseFloat(document.getElementById(‘total’).value);
var percentage = parseFloat(document.getElementById(‘percentage’).value);
var result = (percentage / 100) * total;
document.getElementById(‘result’).value = result.toFixed(2);
}
</script>
</body>
</html>

Read More: Click here

Leave a Comment