-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
45 lines (40 loc) · 1.29 KB
/
app.js
File metadata and controls
45 lines (40 loc) · 1.29 KB
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
45
document.addEventListener('DOMContentLoaded', function() {
// Find the form element
const form = document.querySelector('form');
// Add event listener to the form's submit event
form.addEventListener('submit', function(event) {
event.preventDefault(); // Prevent form submission
// Get form input values
const email = document.querySelector('#emaill').value;
const subject = document.querySelector('#sub').value;
const message = document.querySelector('#mssg').value;
// Create an object with the form data
const formData = {
email: email,
subject: subject,
message: message
};
// Send the form data to the server
fetch('/send-email', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(formData)
})
.then(function(response) {
if (response.ok) {
// Email sent successfully
console.log('Email sent successfully');
// Redirect the user to a success page
window.location.href ="./success.html";
} else {
// Error sending email
console.error('Error sending email');
}
})
.catch(function(error) {
console.error('Error sending email:', error);
});
});
});