Fall 2024 - CS311 - 2 - BC230206139
Fall 2024 - CS311 - 2 - BC230206139
Index.html Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Employee Managment System</title>
<link rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/bootstrp@5.3.0/dist/css/bootstrap.min.css">
<style>
body {
padding: 20px;
background-color: #f8f9fa;
}
.container {
background: white;
padding: 20px;
border-radius: 8px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}
</style>
</head>
<body>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Employee Management System</title>
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css"
rel="stylesheet">
<style>
body {
padding: 20px;
background-color: #f8f9fa;
}
.container {
background: white;
padding: 20px;
border-radius: 8px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}
</style>
</head>
<body>
<div class="container">
<h1 class="text-center mb-4">Employee Management System</h1>
<div class="mb-4">
<button class="btn btn-primary" onclick="displayEmployees()">Display All
Employees</button>
</div>
<div id="employeeDetails" class="mb-4"></div>
<div class="mb-3">
<label for="name" class="form-label">Name</label>
<input type="text" id="name" class="form-control" required>
</div>
<div class="mb-3">
<label for="department" class="form-label">Department</label>
<input type="text" id="department" class="form-control" required>
</div>
<div class="mb-3">
<label for="salary" class="form-label">Salary</label>
<input type="number" id="salary" class="form-control" required>
</div>
<script>
let xmlDoc;
fetch('employees.xml')
.then(response => response.text())
.then(data => {
const parser = new DOMParser();
xmlDoc = parser.parseFromString(data, "text/xml");
})
.catch(error => console.error('Error loading XML:', error));
function displayEmployees() {
const employees = xmlDoc.getElementsByTagName("Employee");
let output = "<table class='table
table-bordered'><thead><tr><th>ID</th><th>Name</th><th>Department</
th><th>Salary</th></tr></thead><tbody>";
output += <tr><td>${id}</td><td>${name}</td><td>${department}</td><td>$
{salary}</td></tr>;
}
output += "</tbody></table>";
document.getElementById("employeeDetails").innerHTML = output;
}
function addEmployee(event) {
event.preventDefault();
const id = document.getElementById("id").value;
const name = document.getElementById("name").value;
const department = document.getElementById("department").value;
const salary = document.getElementById("salary").value;
const newEmployee = xmlDoc.createElement("Employee");
const newId = xmlDoc.createElement("ID");
newId.textContent = id;
const newName = xmlDoc.createElement("Name");
newName.textContent = name;
const newDepartment = xmlDoc.createElement("Department");
newDepartment.textContent = department;
const newSalary = xmlDoc.createElement("Salary");
newSalary.textContent = salary;
newEmployee.appendChild(newId);
newEmployee.appendChild(newName);
newEmployee.appendChild(newDepartment);
newEmployee.appendChild(newSalary);
xmlDoc.getElementsByTagName("Employees")[0].appendChild(newEmployee);
function deleteEmployee(event) {
event.preventDefault();
const id = document.getElementById("deleteId").value;
const employees = xmlDoc.getElementsByTagName("Employee");