-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathd.js
73 lines (63 loc) · 2.94 KB
/
d.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
62
63
64
65
66
67
68
69
70
71
72
73
document.addEventListener("DOMContentLoaded", function() {
const form = document.getElementById("planForm");
const recommendationDiv = document.getElementById("recommendation");
const planRecommendation = document.getElementById("planRecommendation");
const planDetails = document.getElementById("planDetails");
const planImage = document.getElementById("planImage");
// Slide-in effect for the form
document.querySelector(".left-section button").addEventListener("click", function() {
const formSection = document.querySelector(".right-section");
if (formSection.style.transform === "translateX(0px)" || formSection.style.transform === "") {
formSection.style.transform = "translateX(100%)";
} else {
formSection.style.transform = "translateX(0px)";
}
});
form.addEventListener("submit", function(event) {
event.preventDefault();
// Collect and process the form data
collectFormData();
});
});
function collectFormData() {
const ageInput = document.querySelector('input[name="age"]').value;
const occupationInput = document.querySelector('input[name="occupation"]').value;
const locationInput = document.querySelector('input[name="location"]').value;
const travelsInput = document.querySelector('input[name="travels"]').value;
const genderInput = document.querySelector('input[name="gender"]').value;
// Create a query string from the form data
const queryParams = new URLSearchParams();
queryParams.set("age", ageInput);
queryParams.set("occupation", occupationInput);
queryParams.set("location", locationInput);
queryParams.set("travels", travelsInput);
queryParams.set("gender", genderInput);
// Construct the URL with the query string
const apiUrl = "http://127.0.0.1:5500/hack.html?" + queryParams.toString();
// Perform a GET request to send the data to the server
fetch(apiUrl)
.then(response => {
if (response.ok) {
return response.json();
} else {
throw new Error("Request failed.");
}
})
.then(data => {
// Handle the response from the server
console.log(data);
})
.catch(error => {
// Handle errors
console.error(error);
});
}
function fetchDataAndDisplay() {
const ageInput = document.getElementById('age').value;
const occupationInput = document.getElementById('occupation').value;
const locationInput = document.getElementById('location').value;
const travelsInput = document.getElementById('travels').value;
const genderInput = document.getElementById('gender').value;
const outputDiv = document.getElementById('output');
outputDiv.innerHTML = "Age: " + ageInput + "<br>Occupation: " + occupationInput + "<br>Location: " + locationInput + "<br>Travels: " + travelsInput + "<br>Gender: " + genderInput;
}