-
Notifications
You must be signed in to change notification settings - Fork 0
/
contactForm.js
41 lines (37 loc) · 1.34 KB
/
contactForm.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Function to show the notification
function showNotification(message, duration) {
const notification = document.getElementById('notification');
notification.textContent = message;
notification.style.display = 'block';
notification.style.opacity = '1';
// Hide after the specified duration
setTimeout(() => {
notification.style.opacity = '0';
setTimeout(() => {
notification.style.display = 'none';
}, 500);
}, duration);
}
// Add an event listener to the form submit event
document.getElementById('contact-form').addEventListener('submit', function(event) {
event.preventDefault();
// Collect form data
const name = document.getElementById('name').value;
const email = document.getElementById('email').value;
const enquiry = document.getElementById('dropDown').value;
const message = document.getElementById('subject').value;
// Send email via EmailJS
emailjs.send('service_qk3z7ry', 'template_yqja58r', {
name: name,
email: email,
enquiry: enquiry,
message: message
}).then(function(response) {
showNotification('Message sent successfully!', 1000);
setTimeout(() => {
window.location.href = '/';
}, 2000);
}, function(error) {
showNotification('Failed to send message!', 2000);
});
});