document.getElementById('contact-form').addEventListener('submit', async function(e) { e.preventDefault(); // Prevent default form submission // Get form data const name = document.getElementById('name').value; const email = document.getElementById('email').value; const phone_no = document.getElementById('phone').value; const message = document.getElementById('message').value; // Construct the API URL const apiUrl = `https://pieq-data-api.vercel.app/data?email_id=${encodeURIComponent(email)}&name=${encodeURIComponent(name)}&phone_no=${encodeURIComponent(phone_no)}&message=${encodeURIComponent(message)}`; try { // Send GET request to the API const response = await fetch(apiUrl, { method: 'GET', headers: { 'Accept': 'application/json' } }); const result = await response.json(); alert("Message Sent Successfully!"); // Display result message } catch (error) { console.error('Error:', error); document.getElementById('result').innerText = "Something went wrong!"; } // Reset the form this.reset(); });