Ounces to Pounds Converter
by dileepp89
HTML
<div style="max-width="100%" height="100"; padding: 20px; border: 1px solid #ccc; border-radius: 10px; margin: auto;">
<h3>Convert Ounces (oz) to Pounds (lbs)</h3>
<label for="ozInput">Enter weight in ounces:</label>
<input type="number" id="ozInput" placeholder="e.g., 22" style="width: 100%; padding: 8px; margin: 10px 0;" />
<button id="convertButton" style="padding: 10px 20px; cursor: pointer;">Convert</button>
<p id="lbsResult" style="margin-top: 15px; font-weight: bold;"></p>
</div>
JavaScript
document.addEventListener("DOMContentLoaded", function () {
const btn = document.getElementById("convertButton");
btn.addEventListener("click", function () {
const ozInput = document.getElementById("ozInput").value;
if (!ozInput || isNaN(ozInput)) {
document.getElementById("lbsResult").innerText = "Please enter a valid number.";
return;
}
const oz = parseFloat(ozInput);
const lbs = (oz / 16).toFixed(3);
document.getElementById("lbsResult").innerText = `${oz} oz = ${lbs} lbs`;
});
});