Agriproducts Product Viewer
🌿 Explore verified crop inputs | 📦 Real-time cost estimates | 🚜 Mobile-optimized dashboard | 🧪 Formulation insights
❌
const productSelect = document.getElementById("productSelect");
const volumeInput = document.getElementById("volumeInput");
const unitToggle = document.getElementById("unitToggle");
const detailsBox = document.getElementById("detailsBox");
// Populate the dropdown with products
const sortedKeys = Object.keys(products).sort((a, b) => {
return products[a].name.localeCompare(products[b].name);
});
for (const key of sortedKeys) {
const opt = document.createElement("option");
opt.value = key;
opt.textContent = products[key].name;
productSelect.appendChild(opt);
}
function updateDetails() {
const selected = productSelect.value;
const volume = parseFloat(volumeInput.value);
const selectedUnit = unitToggle.value;
if (products[selected]) {
const p = products[selected];
const cost = (volume && p.unit === selectedUnit) ?
(volume * p.price).toLocaleString() :
"—";
detailsBox.innerHTML = `
${p.name}
| Ingredients | ${p.ingredients} |
| Usage | ${p.usage} |
| Usage Interval | ${p.interval} |
| Timing | ${p.timing} |
| Crop Stage & Purpose | ${p.stage} |
| Application Rate | ${p.rate} |
| Unit Price | KES ${p.price}/${p.unit} |
| Estimated Cost | ${p.unit === selectedUnit ? `KES ${cost}` : `⚠️ Unit mismatch`} |
`;
} else {
detailsBox.innerHTML = "";
}
}
productSelect.addEventListener("change", updateDetails);
volumeInput.addEventListener("input", updateDetails);
unitToggle.addEventListener("change", updateDetails);
.
No comments:
Post a Comment