-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
64 lines (52 loc) · 1.76 KB
/
script.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Fetch contact data from an API
fetch('https://api.example.com/contact')
.then(response => response.json())
.then(data => {
const contactInfo = document.createElement('div');
contactInfo.innerHTML = `
<h3>${data.name}</h3>
<p><i class="fa-solid fa-envelope"></i> ${data.email}</p>
<p><i class="fa-solid fa-phone"></i> ${data.phone}</p>
<p><i class="fa-solid fa-map-marker-alt"></i> ${data.address}</p>
`;
document.body.appendChild(contactInfo);
})
.catch(error => {
console.error('Error fetching contact data:', error);
});
// Handle form submission
const form = document.getElementById('contactForm');
form.addEventListener('submit', e => {
e.preventDefault();
const formData = new FormData(form);
const data = {};
for (const [key, value] of formData.entries()) {
data[key] = value;
}
// Construct the mailto URL with form data
const mailtoURL = `mailto:[email protected]?subject=New Message from ${data.name}&body=Name: ${data.name}%0D%0AEmail: ${data.email}%0D%0AMessage: ${data.message}`;
// Open the default email client
window.open(mailtoURL);
// Reset the form
form.reset();
});
function showSidebar() {
const sidebar = document.querySelector('.sidebar');
sidebar.style.display = 'flex';
}
function hideSidebar() {
const sidebar = document.querySelector('.sidebar');
sidebar.style.display = 'none';
}
document.addEventListener('DOMContentLoaded', function () {
const detailsElements = document.querySelectorAll('details');
detailsElements.forEach(function (details) {
details.addEventListener('click', function () {
detailsElements.forEach(function (otherDetails) {
if (otherDetails !== details) {
otherDetails.removeAttribute('open');
}
});
});
});
});