-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindexScript.js
More file actions
48 lines (43 loc) · 1.66 KB
/
indexScript.js
File metadata and controls
48 lines (43 loc) · 1.66 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
46
47
48
document.addEventListener("DOMContentLoaded", function(){
const btnBook = document.querySelector(".btn.btn-primary");
const btnLog = document.querySelector(".btn.btn-outline");
const emailForm = document.getElementById("sendEmail");
btnBook.addEventListener("click",function(){
window.location.href="frontend/ROOM/ROOM CARD/Roomcard.php";
});
btnLog.addEventListener("click",function(){
window.location.href="frontend/Auth/LOGIN/login.php";
});
emailForm.addEventListener("submit",async function(event){
event.defaultPrevented();
const responseText = document.getElementById("contactResponse");
const contactData = {
name: emailForm.name.value.trim(),
email: emailForm.email.value.trim(),
message: emailForm.message.value.trim()
};
try {
const res = await fetch("backend/api/auth/email.php", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(contactData)
});
const result = await res.json();
if (result.success) {
responseText.style.color = "green";
responseText.textContent = "Message sent successfully!";
}
else {
responseText.style.color = "red";
responseText.textContent = result.message;
}
responseText.style.display = "block";
}
catch (error) {
responseText.textContent = "Error sending message.";
responseText.style.display = "block";
}
});
});