document.addEventListener('DOMContentLoaded', function () { const contactForm = document.getElementById('contactForm'); if (contactForm) { contactForm.addEventListener('submit', function (e) { e.preventDefault(); const form = e.target; const formData = new FormData(form); const status = document.getElementById('form-status'); // Basic client-side validation const name = formData.get('name'); const email = formData.get('email'); const message = formData.get('message'); if (!name || !email || !message) { status.innerHTML = '
Please fill out all fields.
'; return; } fetch('contact.php', { method: 'POST', body: formData }) .then(response => response.json()) .then(data => { if (data.success) { status.innerHTML = `
${data.message}
`; form.reset(); } else { status.innerHTML = `
${data.message}
`; } }) .catch(error => { status.innerHTML = '
An error occurred. Please try again.
'; console.error('Error:', error); }); }); } // Fetch and display cyclone data const cycloneDataContainer = document.getElementById('cyclone-data'); if (cycloneDataContainer) { fetch('api/cyclone.php') .then(response => response.json()) .then(data => { if (data && data.length > 0) { let html = ''; data.forEach(alert => { html += `
${alert.headline}

${alert.description.substring(0, 150)}...

Read More
`; }); cycloneDataContainer.innerHTML = html; } else { cycloneDataContainer.innerHTML = '

No active severe weather alerts from the SPC at the moment.

'; } }) .catch(error => { cycloneDataContainer.innerHTML = '

Could not load cyclone data. Please try again later.

'; console.error('Error fetching cyclone data:', error); }); } });