Changed around line 1
+ document.addEventListener('DOMContentLoaded', function() {
+ // Navigation Toggle
+ const navToggle = document.getElementById('navToggle');
+ const navMenu = document.querySelector('.nav-menu');
+
+ navToggle.addEventListener('click', () => {
+ navMenu.classList.toggle('active');
+ });
+
+ // Product Cart Functionality
+ const addToCartButtons = document.querySelectorAll('.add-to-cart');
+ let cartItems = [];
+
+ addToCartButtons.forEach(button => {
+ button.addEventListener('click', (e) => {
+ const product = e.target.closest('.product-card');
+ const productName = product.querySelector('h3').textContent;
+ const productPrice = product.querySelector('.price').textContent;
+
+ cartItems.push({
+ name: productName,
+ price: productPrice
+ });
+
+ updateCart();
+ });
+ });
+
+ function updateCart() {
+ console.log('Cart updated:', cartItems);
+ // Implement cart update logic here
+ }
+
+ // Form Validation
+ const forms = document.querySelectorAll('form');
+
+ forms.forEach(form => {
+ form.addEventListener('submit', (e) => {
+ e.preventDefault();
+ if (validateForm(form)) {
+ submitForm(form);
+ }
+ });
+ });
+
+ function validateForm(form) {
+ let isValid = true;
+ const inputs = form.querySelectorAll('input[required]');
+
+ inputs.forEach(input => {
+ if (!input.value.trim()) {
+ isValid = false;
+ showError(input, 'This field is required');
+ } else {
+ clearError(input);
+ }
+ });
+
+ return isValid;
+ }
+
+ function showError(input, message) {
+ const errorDiv = document.createElement('div');
+ errorDiv.className = 'error-message';
+ errorDiv.textContent = message;
+ input.parentNode.appendChild(errorDiv);
+ }
+
+ function clearError(input) {
+ const errorDiv = input.parentNode.querySelector('.error-message');
+ if (errorDiv) {
+ errorDiv.remove();
+ }
+ }
+
+ function submitForm(form) {
+ // Implement form submission logic here
+ console.log('Form submitted');
+ }
+ });