-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddCourse.html
More file actions
113 lines (113 loc) · 5.38 KB
/
addCourse.html
File metadata and controls
113 lines (113 loc) · 5.38 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Course Management</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="bg-light">
<div class="container py-5">
<div class="row mb-4">
<div class="col text-center">
<h1 class="display-5 fw-bold text-success mb-3">Course Management</h1>
<p class="lead">Add, view, and manage courses easily.</p>
</div>
</div>
<div class="row justify-content-center mb-5">
<div class="col-md-8">
<div class="card shadow">
<div class="card-body">
<h4 class="card-title mb-4 text-primary">Add New Course</h4>
<form id="courseForm" autocomplete="off">
<div class="row g-3 align-items-end">
<div class="col-md-4">
<label for="course_code" class="form-label">Course Code</label>
<input type="text" class="form-control" id="course_code" name="course_code" placeholder="e.g. CS101" required>
</div>
<div class="col-md-5">
<label for="course_name" class="form-label">Course Name</label>
<input type="text" class="form-control" id="course_name" name="course_name" placeholder="e.g. Introduction to CS" required>
</div>
<div class="col-md-2">
<label for="credits" class="form-label">Credits</label>
<input type="number" class="form-control" id="credits" name="credits" placeholder="e.g. 3" min="1" max="10" required>
</div>
<div class="col-md-1 d-grid">
<button type="submit" class="btn btn-success">Add</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<div class="row justify-content-center">
<div class="col-md-10">
<div class="card shadow">
<div class="card-body">
<h4 class="card-title mb-4 text-primary">Existing Courses</h4>
<div class="table-responsive">
<table class="table table-striped table-hover align-middle" id="coursesTable">
<thead class="table-success">
<tr>
<th>Course Code</th>
<th>Course Name</th>
<th>Credits</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<!-- Course rows will be added here -->
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<div class="row mt-5">
<div class="col d-flex justify-content-center gap-3">
<a href="/admin/admin_index.html" class="btn btn-outline-secondary">Back</a>
<a href="/index.html" class="btn btn-danger">Logout</a>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
<script>
const courses = [];
const courseForm = document.getElementById('courseForm');
const coursesTableBody = document.querySelector('#coursesTable tbody');
function renderCourses() {
coursesTableBody.innerHTML = '';
courses.forEach((course, idx) => {
const row = document.createElement('tr');
row.innerHTML = `
<td>${course.course_code}</td>
<td>${course.course_name}</td>
<td>${course.credits}</td>
<td>
<button class="btn btn-sm btn-danger" onclick="deleteCourse(${idx})">Delete</button>
</td>
`;
coursesTableBody.appendChild(row);
});
}
courseForm.addEventListener('submit', function(event) {
event.preventDefault();
const courseCode = document.getElementById('course_code').value.trim();
const courseName = document.getElementById('course_name').value.trim();
const credits = document.getElementById('credits').value.trim();
if (courseCode && courseName && credits) {
courses.push({ course_code: courseCode, course_name: courseName, credits });
renderCourses();
courseForm.reset();
}
});
window.deleteCourse = function(idx) {
courses.splice(idx, 1);
renderCourses();
};
</script>
</body>
</html>