CODE TO CREATE A SCHOOL MANAGMENT SYSTEM

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>School Management System</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f4;
            margin: 0;
            padding: 20px;
        }

        .container {
            max-width: 800px;
            margin: auto;
            padding: 20px;
            background: white;
            border-radius: 8px;
            box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
        }

        h1 {
            text-align: center;
        }

        .form-container {
            margin-bottom: 20px;
        }

        input {
            padding: 10px;
            margin: 5px;
            width: calc(50% - 20px);
        }

        button {
            padding: 10px;
            background: #28a745;
            color: white;
            border: none;
            cursor: pointer;
        }

        button:hover {
            background: #218838;
        }

        table {
            width: 100%;
            border-collapse: collapse;
            margin-bottom: 20px;
        }

        table, th, td {
            border: 1px solid #ddd;
        }

        th, td {
            padding: 10px;
            text-align: left;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>School Management System</h1>

        <div class="form-container">
            <h2>Add Student</h2>
            <input type="text" id="studentName" placeholder="Student Name" required>
            <input type="number" id="studentAge" placeholder="Student Age" required>
            <button onclick="addStudent()">Add Student</button>
        </div>

        <div class="form-container">
            <h2>Add Teacher</h2>
            <input type="text" id="teacherName" placeholder="Teacher Name" required>
            <input type="text" id="teacherSubject" placeholder="Subject" required>
            <button onclick="addTeacher()">Add Teacher</button>
        </div>

        <h2>Students</h2>
        <table id="studentsTable">
            <thead>
                <tr>
                    <th>Name</th>
                    <th>Age</th>
                </tr>
            </thead>
            <tbody>
                <!-- Student records will be added here -->
            </tbody>
        </table>

        <h2>Teachers</h2>
        <table id="teachersTable">
            <thead>
                <tr>
                    <th>Name</th>
                    <th>Subject</th>
                </tr>
            </thead>
            <tbody>
                <!-- Teacher records will be added here -->
            </tbody>
        </table>
    </div>

    <script>
        let students = [];
        let teachers = [];

        function addStudent() {
            const name = document.getElementById("studentName").value;
            const age = document.getElementById("studentAge").value;

            if (name && age) {
                students.push({ name, age });
                displayStudents();
                clearStudentInput();
            } else {
                alert("Please fill in all fields.");
            }
        }

        function displayStudents() {
            const tableBody = document.getElementById("studentsTable").getElementsByTagName('tbody')[0];
            tableBody.innerHTML = "";

            students.forEach(student => {
                const row = tableBody.insertRow();
                row.insertCell(0).innerText = student.name;
                row.insertCell(1).innerText = student.age;
            });
        }

        function clearStudentInput() {
            document.getElementById("studentName").value = "";
            document.getElementById("studentAge").value = "";
        }

        function addTeacher() {
            const name = document.getElementById("teacherName").value;
            const subject = document.getElementById("teacherSubject").value;

            if (name && subject) {
                teachers.push({ name, subject });
                displayTeachers();
                clearTeacherInput();
            } else {
                alert("Please fill in all fields.");
            }
        }

        function displayTeachers() {
            const tableBody = document.getElementById("teachersTable").getElementsByTagName('tbody')[0];
            tableBody.innerHTML = "";

            teachers.forEach(teacher => {
                const row = tableBody.insertRow();
                row.insertCell(0).innerText = teacher.name;
                row.insertCell(1).innerText = teacher.subject;
            });
        }

        function clearTeacherInput() {
            document.getElementById("teacherName").value = "";
            document.getElementById("teacherSubject").value = "";
        }
    </script>
</body>
</html>
HTML

Leave a Reply

Your email address will not be published. Required fields are marked *

Resize text
Scroll to Top