<!DOCTYPE html>
<html>
<head>
<title>Electricity Bill Calculator</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
background-color: #f0f9ff; /* Light Blue Background */
}
.container {
background-color: #e0f2fe; /* Soft Blue Container */
padding: 30px;
border-radius: 12px;
box-shadow: 0 0 <15px rgba(0, 0, 0, 0.2);
max-width: 500px;
margin: 0 auto;
}
h1 {
color: #0c4a6e; /* Dark Blue Title */
text-align: center;
margin-bottom: 20px;
}
label {
display: block;
margin-bottom: 8px;
font-weight: bold;
color: #075985;
}
input[type="text"], input[type="number"], input[type="tel"] {
width: calc(100% - 20px);
padding: 10px;
margin-bottom: 15px;
border: 1px solid #38bdf8;
border-radius: 6px;
}
button {
background-color: #0284c7; /* Blue Button */
color: white;
padding: 12px 20px;
border: none;
border-radius: 6px;
cursor: pointer;
width: 100%;
font-size: 16px;
}
button:hover {
background-color: #0369a1; /* Darker Blue on Hover */
}
.result {
margin-top: 20px;
padding: 15px;
background-color: #ffffff;
border-radius: 6px;
}
.error {
color: red;
margin-bottom: 10px;
}
.bill-details {
text-align: left;
color: #0c4a6e;
}
</style>
</head>
<body>
<div class="container">
<h1>Electricity Bill Calculator</h1>
<form method="post" action="" onsubmit="return validateForm()">
<label for="name">Customer Name:</label>
<input type="text" id="name" name="name" required>
<label for="phone">Phone Number:</label>
<input type="tel" id="phone" name="phone" pattern="[0-9]{10}" placeholder="Enter 10-digit number" required>
<div id="phoneError" class="error"></div>
<label for="units">Units Consumed:</label>
<input type="number" id="units" name="units" min="0" required>
<div id="unitsError" class="error"></div>
<button type="submit" name="submit">Calculate Bill</button>
</form>
<div class="result">
<?php
if (isset($_POST['submit'])) { $units = $_POST['units'];
$bill = 0;
if ($units <= 100) {
$bill = 0;
} else if ($units > 100 && $units <= 200) {
$remaining_units = $units - 100;
$bill = $remaining_units * 4.00;
} else if ($units > 200 && $units <= 300) {
$temp = 100 * 4.00;
$remaining_units = $units - 200;
$bill = $temp + ($remaining_units * 5.20);
} else {
$temp = (100 * 4.00) + (100 * 5.20);
$remaining_units = $units - 300;
$bill = $temp + ($remaining_units * 6.50);
}
echo "<div class='bill-details'>";
echo "<h3>Bill Details</h3>";
echo "<p><strong>Name:</strong> " . $name . "</p>";
echo "<p><strong>Phone:</strong> " . $phone . "</p>";
echo "<p><strong>Units Consumed:</strong> " . $units . " units</p>";
echo "<h3>Total Bill Amount: Rs. " . number_format($bill, 2) . "</h3>"; echo "</div>";
}
?>
</div>
</div>
<script>
function validateForm() {
var units = document.getElementById("units").value;
var phone = document.getElementById("phone").value;
var unitsError = document.getElementById("unitsError");
var phoneError = document.getElementById("phoneError");
if (units < 0) {
unitsError.textContent = "Units consumed cannot be negative.";
return false;
} else {
unitsError.textContent = "";
}
if (!/^[0-9]{10}$/.test(phone)) {
phoneError.textContent = "Phone number must be 10 digits.";
return false;
} else {
phoneError.textContent = "";
}
return true;
}
</script>
</body>
</html>