document.addEventListener('DOMContentLoaded', function () { const orderForm = document.getElementById('orderForm'); if (!orderForm) return; const priceSummary = document.getElementById('price-summary'); const fileInput = document.getElementById('document'); const specificReqBtn = document.getElementById('specificReqBtn'); const basePrices = { printType: { 'one-sided': 0.10, 'both-sided': 0.18 }, color: { 'bw': 0.05, 'color': 0.25 }, paperSize: { 'a4': 0.02, 'jumbo': 0.05 }, pagesPerSheet: { '1': 0, '2': 0.01, '4': 0.02 } }; function calculatePrice() { const formData = new FormData(orderForm); const printType = formData.get('printType'); const color = formData.get('color'); const paperSize = formData.get('paperSize'); const pagesPerSheet = formData.get('pagesPerSheet'); const quantity = parseInt(formData.get('quantity') || '1', 10); let cost = 0; cost += basePrices.printType[printType] || 0; cost += basePrices.color[color] || 0; cost += basePrices.paperSize[paperSize] || 0; cost += basePrices.pagesPerSheet[pagesPerSheet] || 0; const total = cost * quantity; priceSummary.textContent = `$${total.toFixed(2)}`; } orderForm.addEventListener('change', calculatePrice); orderForm.addEventListener('input', calculatePrice); orderForm.addEventListener('submit', function(e) { if (!fileInput.files || fileInput.files.length === 0) { e.preventDefault(); alert('Please upload a document before submitting.'); fileInput.focus(); } }); if (specificReqBtn) { specificReqBtn.addEventListener('click', function() { alert('Please visit the shop for more specific requirements.'); }); } calculatePrice(); });