Changed around line 1
+ document.addEventListener('DOMContentLoaded', () => {
+ const ticketForm = document.getElementById('ticketForm');
+ const trackForm = document.getElementById('trackForm');
+ const statusResult = document.getElementById('statusResult');
+
+ // Generate random ticket ID
+ const generateTicketId = () => {
+ return 'TKT-' + Math.random().toString(36).substr(2, 9).toUpperCase();
+ };
+
+ // Store tickets in localStorage
+ const tickets = JSON.parse(localStorage.getItem('tickets')) || {};
+
+ ticketForm.addEventListener('submit', (e) => {
+ e.preventDefault();
+
+ const ticketId = generateTicketId();
+ const ticket = {
+ id: ticketId,
+ name: document.getElementById('name').value,
+ email: document.getElementById('email').value,
+ category: document.getElementById('category').value,
+ priority: document.getElementById('priority').value,
+ description: document.getElementById('description').value,
+ status: 'Open',
+ created: new Date().toISOString()
+ };
+
+ tickets[ticketId] = ticket;
+ localStorage.setItem('tickets', JSON.stringify(tickets));
+
+ // Simulate email notification
+ console.log(`Email sent to ${ticket.email} with ticket ID: ${ticketId}`);
+
+ // Show success message
+ alert(`Ticket created successfully!\nYour ticket ID is: ${ticketId}`);
+ ticketForm.reset();
+ });
+
+ trackForm.addEventListener('submit', (e) => {
+ e.preventDefault();
+
+ const ticketId = document.getElementById('ticketId').value;
+ const ticket = tickets[ticketId];
+
+ statusResult.classList.remove('hidden', 'success', 'error');
+
+ if (ticket) {
+ statusResult.textContent = `
+ Status: ${ticket.status}
+ Category: ${ticket.category}
+ Priority: ${ticket.priority}
+ Created: ${new Date(ticket.created).toLocaleString()}
+ `;
+ statusResult.classList.add('success');
+ } else {
+ statusResult.textContent = 'Ticket not found. Please check the ID and try again.';
+ statusResult.classList.add('error');
+ }
+ });
+
+ // Form validation
+ const inputs = document.querySelectorAll('input, select, textarea');
+ inputs.forEach(input => {
+ input.addEventListener('invalid', (e) => {
+ e.preventDefault();
+ input.classList.add('error');
+ });
+
+ input.addEventListener('input', () => {
+ input.classList.remove('error');
+ });
+ });
+ });