function calculateFillRate() {
var quantityOrdered = document.getElementById("quantityOrdered").value;
var quantityFulfilled = document.getElementById("quantityFulfilled").value;
var fillRateOutput = document.getElementById("fillRateOutput");
// Clear previous results
fillRateOutput.innerHTML = "";
// Input validation
if (isNaN(quantityOrdered) || quantityOrdered <= 0) {
fillRateOutput.innerHTML = "Please enter a valid positive number for Quantity Ordered.";
return;
}
if (isNaN(quantityFulfilled) || quantityFulfilled parseFloat(quantityOrdered)) {
fillRateOutput.innerHTML = "Quantity Fulfilled cannot be greater than Quantity Ordered.";
return;
}
// Calculation logic
var fillRate = (parseFloat(quantityFulfilled) / parseFloat(quantityOrdered)) * 100;
// Display result
fillRateOutput.innerHTML = "Your Fill Rate is:
" + fillRate.toFixed(2) + "%";
}
.calculator-wrapper {
font-family: sans-serif;
border: 1px solid #ddd;
padding: 20px;
border-radius: 8px;
max-width: 500px;
margin: 20px auto;
background-color: #f9f9f9;
}
.calculator-form h2 {
text-align: center;
margin-bottom: 15px;
color: #333;
}
.calculator-form p {
margin-bottom: 20px;
line-height: 1.6;
color: #555;
}
.form-group {
margin-bottom: 15px;
}
.form-group label {
display: block;
margin-bottom: 5px;
font-weight: bold;
color: #444;
}
.form-group input[type="number"] {
width: calc(100% – 12px);
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box; /* Ensures padding doesn't affect width */
}
.calculator-form button {
width: 100%;
padding: 10px 15px;
background-color: #007bff;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
transition: background-color 0.3s ease;
}
.calculator-form button:hover {
background-color: #0056b3;
}
.calculator-result {
margin-top: 20px;
padding-top: 15px;
border-top: 1px solid #eee;
text-align: center;
}
.calculator-result h3 {
color: #333;
margin-bottom: 10px;
}
#fillRateOutput strong {
color: #28a745;
font-size: 1.2em;
}