pieq / script.js
Divyanshyadav007's picture
Update script.js
67efeab verified
Raw
History Blame Contribute Delete
1.19 kB
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();
});