-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhome.html
79 lines (69 loc) · 2.25 KB
/
home.html
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
74
75
76
77
78
79
<!DOCTYPE html>
<html>
<head>
<title>Home</title>
<!-- <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> -->
<script>
//getting the form input fields in formdata array when form is submitted
const formData = {};
function submit(){
// console.log("??????");
var formElements = document.querySelector("#signup-form").elements
for(let i=0;i<formElements.length;i++){
formData[formElements[i].name] = formElements[i].value;
// console.log("check");
}
console.log(formData);
postLocation();
}
//submitting the location to server
function postLocation(){
navigator.geolocation.getCurrentPosition(function(position) {
fetch('http://localhost:3000/api/locations',{
// mode:"no-cors",
method:"POST",
headers: {
"Content-Type": "application/json",
// "Content-Type": "application/x-www-form-urlencoded",
},
body: JSON.stringify({"lat":position.coords.latitude,"long":position.coords.longitude})
}).then(res=>{
return res.json();
}).then(res=>{
console.log(res._id);
postUser(res._id);
})
});
}
//submitting user
function postUser(location){
if(formData['isStudent'] == 'on') formData['isStudent'] = true;
else formData['isStudent'] = false;
formData['location'] = location;
fetch('http://localhost:3000/api/users',{
method:"POST",
headers: {
"Content-Type": "application/json",
// "Content-Type": "application/x-www-form-urlencoded",
},
body: JSON.stringify(formData),
})
.then(res=> {return res.json()})
.then(resp=>{console.log(resp)})
}
</script>
</head>
<body>
<form id="signup-form">
name:<input type="text" name="name" required ><br>
phone number:<input type="number" name="phone" required><br>
isStudent:<input type="checkbox" name="isStudent" required><br>
email:<input type="text" name="email" required><br>
password:<input type="password" name="password" required><br>
username:<input type="text" name="username" required><br>
course:<input type="text" name="course" required><br>
<!-- <input type="submit" value="Register"> -->
</form>
<button onclick="submit()">Register</button>
</body>
</html>