-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateStudent.html
More file actions
94 lines (78 loc) · 3.19 KB
/
createStudent.html
File metadata and controls
94 lines (78 loc) · 3.19 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
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<html>
<head>
<title> Student Genius</title>
<link rel="stylesheet" href="createStudentStyles.css" type="text/css">
</head>
<body>
<div id="wrapper">
<!-- website title and logo -->
<div id="banner">
<input type="image" src="logo.png" id="home" onclick="redirect()" width="200" height="98"
style="float: left;">
<h1 align="center">Student Genius</h1>
</div>
<!-- a form in the boxed div with textboxes and submit button -->
<div id="main-content" align="center">
<div id="menu">
<div id="box" align="center">
<h1>Create A Student Account</h1>
<form id="createUser">
<label for="name">Name:</label>
<input type="text" id="name" required><br><br>
<label for="name">Grade:</label>
<input type="text" id="grade" required><br><br>
<label for="name">ID: </label>
<input type="text" id="ID" required><br><br>
<label for="email">Email: </label>
<input type="text" id="mail" required><br><br>
<label for="password">Password:</label>
<input type="password" id="password" required><br><br>
<input type="submit" value="Create Account">
</form>
</div>
</div>
</div>
<div id="footer"></div>
</div>
<script>
// sends all the given inputs to the API route to update the database
function create() {
const data = {
id: document.getElementById("ID").value,
name: document.getElementById("name").value,
grade: document.getElementById("grade").value,
pwd: document.getElementById("password").value,
email: document.getElementById("mail").value
};
fetch('http://localhost:3000/createStudent', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(data),
})
.then(response => response.json())
.then(result => {
// setTimeout(() => { window.location = "createSuccess.html" }, 500);
window.location = "createSuccess.html";
console.log(result);
})
.catch((error) => {
console.log("error:", error);
alert("This User Already Exists")
});
}
// trigger the create function when submit button is clicked
form = document.getElementById("createUser");
form.addEventListener('submit', function (event) {
// Prevent the default form submission behavior
event.preventDefault();
create();
});
// redirect to admin home page
function redirect() {
window.location = "adminIndex.html";
}
</script>
</body>
</html>