-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
44 lines (37 loc) · 1.39 KB
/
main.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
document.addEventListener("DOMContentLoaded", function() {
const form = document.querySelector("form");
form.addEventListener("submit", async function(event) {
event.preventDefault();
const formData = new FormData(form);
const data = Object.fromEntries(formData);
try {
const response = await fetch(form.action, {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(data)
});
if (response.ok) {
alert("Mensaje enviado correctamente!");
form.reset();
} else {
alert("Error al enviar el mensaje.");
}
} catch (error) {
console.error("Error:", error);
alert("Error al enviar el mensaje.");
}
});
const modeToggle = document.getElementById("mode-toggle");
modeToggle.addEventListener("click", function() {
document.body.classList.toggle("dark-mode");
document.body.classList.toggle("light-mode");
// Update icon based on theme
if (document.body.classList.contains("dark-mode")) {
modeToggle.innerHTML = '<i class="fas fa-moon moon-icon"></i>';
} else {
modeToggle.innerHTML = '<i class="fas fa-sun sun-icon"></i>';
}
});
});