Here's the complete implementation of the "Instant Moving Quote" tool as per the requirements:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Instant Moving Quote</title>
<style>
:root {
--primary-color: #2196F3;
--secondary-color: #4CAF50;
--background-color: #f5f5f5;
--text-color: #333;
--accent-color: #FF9800;
--border-radius: 4px;
--spacing: 1rem;
}
/* Layout Styles */
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: var(--background-color);
}
.container {
display: flex;
flex-wrap: wrap;
gap: var(--spacing);
max-width: 1200px;
margin: 0 auto;
padding: var(--spacing);
}
.form-section, .preview-section {
flex: 1;
min-width: 300px;
padding: 1rem;
}
@media (max-width: 920px) {
.container {
flex-direction: column;
}
}
/* Form Styles */
form {
display: grid;
gap: 1rem;
}
.form-group {
display: flex;
flex-direction: column;
}
label {
margin-bottom: 0.5rem;
}
input, select, textarea {
width: 100%;
padding: 0.5rem;
margin: 0.25rem 0;
border: 1px solid var(--accent-color);
border-radius: var(--border-radius);
}
input:focus, select:focus, textarea:focus {
outline: none;
border-color: var(--primary-color);
box-shadow: 0 0 0 2px rgba(33, 150, 243, 0.3);
}
/* Validation states */
input:invalid, select:invalid, textarea:invalid {
border-color: red;
}
input:valid, select:valid, textarea:valid {
border-color: green;
}
/* Quote Preview Styles */
.preview-section {
background: white;
padding: 1rem;
border: 1px solid var(--accent-color);
border-radius: var(--border-radius);
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.preview-badge {
display: inline-block;
padding: 0.25rem 0.5rem;
background-color: var(--accent-color);
color: white;
border-radius: var(--border-radius);
margin-bottom: 1rem;
}
.preview-content {
margin-bottom: 1rem;
}
.quote-number {
font-weight: bold;
}
table {
width: 100%;
border-collapse: collapse;
margin: 1rem 0;
}
th, td {
border: 1px solid #ddd;
padding: 0.5rem;
}
th {
background-color: var(--primary-color);
color: white;
}
.total-row {
font-weight: bold;
}
/* Action Buttons */
.actions button {
background: var(--primary-color);
color: white;
border: none;
padding: 0.75rem 1.5rem;
border-radius: var(--border-radius);
cursor: pointer;
transition: transform 0.2s ease;
}
.actions button:disabled {
background: #ddd;
cursor: not-allowed;
}
.actions button:hover {
background: var(--secondary-color);
}
.actions button:active {
transform: scale(0.98);
}
/* Print Styles */
@media print {
.form-section, .preview-section .actions {
display: none;
}
.preview-section {
width: 100%;
}
.preview-content {
background: white;
color: black;
font-size: 12pt;
}
table {
border-collapse: collapse;
width: 100%;
}
th, td {
border: 1px solid #000;
}
}
</style>
</head>
<body>
<div class="container">
<section class="form-section">
<h2>Move Details</h2>
<form id="movingForm">
<div class="form-group">
<label for="fullName">Full Name</label>
<input type="text" id="fullName" required>
</div>
<div class="form-group">
<label for="email">Email</label>
<input type="email" id="email" required>
</div>
<div class="form-group">
<label for="phone">Phone Number</label>
<input type="tel" id="phone" required>
</div>
<div class="form-group">
<label for="moveDate">Preferred Move Date</label>
<input type="date" id="moveDate" required>
</div>
<div class="form-group">
<label for="moveSize">Size of Move</label>
<select id="moveSize" required>
<option value="">Select...</option>
<option value="Studio">Studio</option>
<option value="1 Bedroom">1 Bedroom</option>
<option value="2 Bedroom">2 Bedroom</option>
<option value="3+ Bedroom">3+ Bedroom</option>
</select>
</div>
<div class="form-group">
<label for="origin">Origin Address</label>
<textarea id="origin" required></textarea>
</div>
<div class="form-group">
<label for="destination">Destination Address</label>
<textarea id="destination" required></textarea>
</div>
<div class="form-group">
<fieldset>
<legend>Optional Services</legend>
<div>
<input type="checkbox" id="packing" data-price="500">
<label for="packing">Packing Service (R 500)</label>
</div>
<div>
<input type="checkbox" id="storage" data-price="300">
<label for="storage">Storage Required (R 300)</label>
</div>
<div>
<input type="checkbox" id="insurance" data-price="200">
<label for="insurance">Transit Insurance (R 200)</label>
</div>
</fieldset>
</div>
</form>
</section>
<section class="preview-section">
<h2 class="preview-badge">Preview</h2>
<div class="preview-content" aria-live="polite">
<p><strong>Quote Number:</strong> <span class="quote-number">----</span></p>
<p><strong>Client Name:</strong> <span class="client-name">----</span></p>
<p><strong>Contact:</strong> <span class="contact">----</span></p>
<p><strong>Move Date:</strong> <span class="move-date">----</span></p>
<p><strong>Move Size:</strong> <span class="move-size">----</span></p>
<p><strong>Origin Address:</strong> <span class="origin">----</span></p>
<p><strong>Destination Address:</strong> <span class="destination">----</span></p>
<table id="services-table">
<thead>
<tr>
<th>Service</th>
<th>Price</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<div class="totals">
<p><strong>Subtotal:</strong> <span class="subtotal">R 0.00</span></p>
<p><strong>VAT (15%):</strong> <span class="vat">R 0.00</span></p>
<p class="total-row"><strong>Grand Total:</strong> <span class="total">R 0.00</span></p>
</div>
</div>
<div class="actions">
<button id="emailButton" disabled>Send Quote via Email</button>
<button id="printButton" disabled>Print/Save PDF</button>
</div>
</section>
</div>
<script>
// Helper Functions
function getQuoteNumber() {
const now = new Date();
const year = now.getFullYear().toString().slice(-2);
const month = String(now.getMonth() + 1).padStart(2, '0');
const day = String(now.getDate()).padStart(2, '0');
const hours = String(now.getHours()).padStart(2, '0');
const minutes = String(now.getMinutes()).padStart(2, '0');
return `${year}${month}${day}-${hours}${minutes}`;
}
function formatCurrency(number) {
return new Intl.NumberFormat('en-ZA', { style: 'currency', currency: 'ZAR' }).format(number);
}
function addTableRow(tableBody, serviceName, price) {
const row = tableBody.insertRow();
const cell1 = row.insertCell(0);
const cell2 = row.insertCell(1);
cell1.textContent = serviceName;
cell2.textContent = formatCurrency(price);
}
// Form Handling
document.addEventListener('DOMContentLoaded', () => {
const moveDateInput = document.getElementById('moveDate');
const today = new Date().toISOString().split('T')[0];
moveDateInput.min = today;
// Event Listeners
document.querySelectorAll('input, select, textarea').forEach(element => {
element.addEventListener('input', updateQuote);
});
document.getElementById('emailButton').addEventListener('click', handleEmail);
document.getElementById('printButton').addEventListener('click', () => window.print());
});
function updateQuote() {
// Get form values
const fullName = document.getElementById('fullName').value;
const email = document.getElementById('email').value;
const phone = document.getElementById('phone').value;
const moveDate = document.getElementById('moveDate').value;
const moveSize = document.getElementById('moveSize').value;
const origin = document.getElementById('origin').value;
const destination = document.getElementById('destination').value;
const packing = document.getElementById('packing').checked;
const storage = document.getElementById('storage').checked;
const insurance = document.getElementById('insurance').checked;
// Calculate subtotal
let subtotal = 0;
if (packing) subtotal += 500;
if (storage) subtotal += 300;
if (insurance) subtotal += 200;
const vat = subtotal * 0.15;
const total = subtotal + vat;
// Update preview content
const previewContent = document.querySelector('.preview-content');
previewContent.querySelector('.quote-number').textContent = getQuoteNumber();
previewContent.querySelector('.client-name').textContent = fullName;
previewContent.querySelector('.contact').textContent = `${phone} | ${email}`;
previewContent.querySelector('.move-date').textContent = moveDate;
previewContent.querySelector('.move-size').textContent = moveSize;
previewContent.querySelector('.origin').textContent = origin;
previewContent.querySelector('.destination').textContent = destination;
// Update services table
const tableBody = previewContent.querySelector('#services-table tbody');
tableBody.innerHTML = '';
if (packing) addTableRow(tableBody, 'Packing Service', 500);
if (storage) addTableRow(tableBody, 'Storage Required', 300);
if (insurance) addTableRow(tableBody, 'Transit Insurance', 200);
// Update totals
previewContent.querySelector('.subtotal').textContent = formatCurrency(subtotal);
previewContent.querySelector('.vat').textContent = formatCurrency(vat);
previewContent.querySelector('.total').textContent = formatCurrency(total);
// Update buttons and badge
const form = document.getElementById('movingForm');
const isValid = form.checkValidity();
const emailButton = document.getElementById('emailButton');
const printButton = document.getElementById('printButton');
const previewBadge = previewContent.querySelector('.preview-badge');
if (isValid) {
emailButton.disabled = false;
printButton.disabled = false;
previewBadge.textContent = 'Quote';
previewBadge.style.backgroundColor = '#4CAF50';
// Smooth scroll on mobile
if (window.innerWidth < 920) {
previewContent.scrollIntoView({ behavior: 'smooth', block: 'start' });
}
} else {
emailButton.disabled = true;
printButton.disabled = true;
previewBadge.textContent = 'Preview';
previewBadge.style.backgroundColor = '#FF9800';
}
}
function handleEmail() {
const subject = `Moving Quote from [Your Company Name]`;
const body = `Dear ${document.getElementById('fullName').value},\n\nYour moving quote details:\n\n` +
`Quote Number: ${getQuoteNumber()}\n` +
`Client Name: ${document.getElementById('fullName').value}\n` +
`Contact: ${document.getElementById('phone').value} | ${document.getElementById('email').value}\n` +
`Move Date: ${document.getElementById('moveDate').value}\n` +
`Move Size: ${document.getElementById('moveSize').value}\n` +
`Origin Address: ${document.getElementById('origin').value}\n` +
`Destination Address: ${document.getElementById('destination').value}\n\n` +
`Services Selected:\n` +
(document.getElementById('packing').checked ? "- Packing Service\n" : "") +
(document.getElementById('storage').checked ? "- Storage Required\n" : "") +
(document.getElementById('insurance').checked ? "- Transit Insurance\n" : "") +
`Subtotal: ${document.querySelector('.subtotal').textContent}\n` +
`VAT (15%): ${document.querySelector('.vat').textContent}\n` +
`Total: ${document.querySelector('.total').textContent}`;
const mailtoLink = `mailto:?subject=${encodeURIComponent(subject)}&body=${encodeURIComponent(body)}`;
window.location.href = mailtoLink;
}
</script>
</body>
</html>
This implementation includes all required features and some bonus elements like smooth scrolling on mobile and subtle button animations. The solution uses pure HTML/CSS/JS without any frameworks, follows all functional and design requirements, and includes proper accessibility features like ARIA live regions. The quote dynamically updates as users fill out the form, and the print functionality provides clean print-ready output.