Assignment 2
Assignment 2
Index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<style>
body {f
margin: 20px;
display: flex;
flex-direction: column;
align-items: center;
background-color: #f4f4f9;
h1 {
font-size: 2.5em;
color: #333;
margin-bottom: 20px;
table {
width: 90%;
border-collapse: collapse;
margin-bottom: 20px;
table, th, td {
border: 1px solid #ddd;
th, td {
padding: 12px;
text-align: left;
th {
background-color: #007BFF;
color: white;
.form-container {
width: 60%;
margin-bottom: 20px;
padding: 20px;
background-color: white;
border-radius: 10px;
display: flex;
flex-direction: column;
gap: 15px;
.form-container h2 {
margin-bottom: 15px;
font-size: 1.5em;
color: #007BFF;
text-align: center;
.form-container label {
display: inline-block;
width: 150px;
font-weight: bold;
margin-right: 10px;
text-align: right;
.form-container input {
flex-grow: 1;
padding: 10px;
border-radius: 5px;
.form-container button {
padding: 12px;
background-color: #28a745;
color: white;
border: none;
border-radius: 5px;
font-size: 1em;
cursor: pointer;
.form-container button:hover {
background-color: #218838;
button {
background-color: #007BFF;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 1em;
margin-bottom: 20px;
button:hover {
background-color: #0056b3;
#employeeTable {
width: 90%;
margin-top: 20px;
.form-group {
display: flex;
align-items: center;
gap: 10px;
</style>
</head>
<body>
<h2>Employee Details</h2>
<div id="employeeTable"></div>
<div class="form-container">
<form id="addEmployeeForm">
<div class="form-group">
<label for="empID">ID:</label>
</div>
<div class="form-group">
<label for="empName">Name:</label>
</div>
<div class="form-group">
<label for="empDept">Department:</label>
</div>
<div class="form-group">
<label for="empSalary">Salary:</label>
</div>
</form>
</div>
<div class="form-container">
<h2>Delete Employee</h2>
<form id="deleteEmployeeForm">
<div class="form-group">
<label for="deleteEmpID">ID:</label>
</div>
</form>
</div>
<script>
let xmlDoc;
function loadXML() {
xhr.onload = function () {
} else {
};
xhr.send();
function displayEmployees() {
let html =
"<table><tr><th>ID</th><th>Name</th><th>Department</th><th>Salary</th></tr>";
const id = employees[i].getElementsByTagName("ID")[0].textContent;
html +=
`<tr><td>${id}</td><td>${name}</td><td>${dept}</td><td>${salary}</td></tr>`;
html += "</table>";
document.getElementById("employeeTable").innerHTML = html;
function addEmployee() {
const id = document.getElementById("empID").value;
newID.textContent = id;
newName.textContent = name;
newDept.textContent = dept;
newSalary.textContent = salary;
newEmployee.appendChild(newID);
newEmployee.appendChild(newName);
newEmployee.appendChild(newDept);
newEmployee.appendChild(newSalary);
xmlDoc.documentElement.appendChild(newEmployee);
displayEmployees();
document.getElementById("addEmployeeForm").reset();
// Delete an employee
function deleteEmployee() {
const id = employees[i].getElementsByTagName("ID")[0].textContent;
if (id === idToDelete) {
xmlDoc.documentElement.removeChild(employees[i]);
displayEmployees();
document.getElementById("deleteEmployeeForm").reset();
return;
window.onload = loadXML;
</script>
</body>
</html>
Employees.xml
<Employees>
<Employee>
<ID>01</ID>
<Name>Aatif ali</Name>
<Department>CS</Department>
<Salary> 204000</Salary>
</Employee>
<Employee>
<br>
<ID>02</ID>
<Name>A.Malik</Name>
<Department>IT</Department>
<Salary>5000</Salary>
</Employee>
<Employee>
<br>
<ID>03</ID>
<Name>Noor ahmed</Name>
<Department>IT department</Department>
<Salary>9000000</Salary>
</Employee>
</Employees>