2024-08-31 13:06:03 +00:00
|
|
|
document.getElementById('applicationForm').addEventListener('submit', function(event) {
|
2024-11-14 13:53:04 +00:00
|
|
|
event.preventDefault();
|
2024-08-31 13:06:03 +00:00
|
|
|
|
|
|
|
// Get form data
|
|
|
|
const formData = new FormData(this);
|
|
|
|
const data = Object.fromEntries(formData.entries());
|
|
|
|
|
2024-11-18 16:11:03 +00:00
|
|
|
// Clear previous messages
|
|
|
|
const responseMessage = document.getElementById('responseMessage');
|
|
|
|
responseMessage.textContent = '';
|
|
|
|
responseMessage.className = '';
|
|
|
|
|
2024-11-14 13:53:04 +00:00
|
|
|
// Send form data to server-side endpoint
|
|
|
|
fetch('/submit', {
|
2024-08-31 13:06:03 +00:00
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
},
|
|
|
|
body: JSON.stringify(data),
|
|
|
|
})
|
2024-11-18 16:11:03 +00:00
|
|
|
.then(response => {
|
|
|
|
if (!response.ok) {
|
|
|
|
// If the response status is not OK, throw an error
|
|
|
|
return response.json().then(err => {
|
|
|
|
throw new Error(err.message || 'An error occurred');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return response.json();
|
|
|
|
})
|
2024-08-31 13:06:03 +00:00
|
|
|
.then(result => {
|
|
|
|
console.log('Success:', result);
|
2024-11-18 16:11:03 +00:00
|
|
|
responseMessage.textContent = 'Thank you for your application!';
|
|
|
|
responseMessage.className = 'success';
|
2024-08-31 13:06:03 +00:00
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
console.error('Error:', error);
|
2024-11-18 16:11:03 +00:00
|
|
|
responseMessage.textContent = `Error: ${error.message}`;
|
|
|
|
responseMessage.className = 'error';
|
2024-08-31 13:06:03 +00:00
|
|
|
});
|
|
|
|
});
|