-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvolunteer-form.js
44 lines (39 loc) · 1.49 KB
/
volunteer-form.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
42
43
44
// 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);
}
document.addEventListener('DOMContentLoaded', function() {
const form = document.querySelector('.volunteer-form');
form.addEventListener('submit', function(event) {
event.preventDefault();
// Get form values
const name = document.getElementById('volunteer-name').value;
const email = document.getElementById('volunteer-email').value;
const message = document.getElementById('volunteer-message').value;
// Send the email
emailjs.send("service_g0xjxy7", "template_yr9w1t9", {
from_name: name,
from_email: email,
message: message
})
.then(function(response) {
console.log('SUCCESS!', response.status, response.text);
showNotification('Message sent successfully!', 1000);
contactForm.reset();
}, function(error) {
console.log('FAILED...', error);
showNotification('Failed to send message!', 2000);
contactForm.reset();
});
});
});