-
Notifications
You must be signed in to change notification settings - Fork 0
/
add-student.js
56 lines (53 loc) · 2.21 KB
/
add-student.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
async function onSubmit(event) {
event.preventDefault();
const first_name = document.getElementById('first_name').value;
const legal_first_name = document.getElementById('legal_first_name').value;
const last_name = document.getElementById('last_name').value;
const department = document.getElementById('department').value;
const pratt_id = document.getElementById('pratt_id').value;
const student_category = document.getElementById('student_category').value;
const email = document.getElementById('email').value;
const sw_status = document.getElementById('sw_status').checked;
const rc_status = document.getElementById('rc_status').value;
const admin_notes = document.getElementById('admin_notes').value;
const courses = document.getElementById('courses').value;
const approvals = document.getElementById('approvals').value;
const response = await fetch('/api/students', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
first_name,
legal_first_name,
last_name,
department,
pratt_id,
student_category,
email,
sw_status,
rc_status,
admin_notes,
courses,
approvals
}),
});
if (response.ok) {
alert('Student added successfully');
// Clear form fields after successful submission
document.getElementById('first_name').value = '';
document.getElementById('legal_first_name').value = '';
document.getElementById('last_name').value = '';
document.getElementById('department').value = 'DDA';
document.getElementById('pratt_id').value = '';
document.getElementById('student_category').value = '';
document.getElementById('email').value = '';
document.getElementById('sw_status').checked = false;
document.getElementById('rc_status').value = '';
document.getElementById('admin_notes').value = '';
document.getElementById('courses').value = '';
document.getElementById('approvals').value = '';
} else {
alert('Failed to add student');
}
}