Untitled
unknown
plain_text
5 months ago
2.0 kB
4
Indexable
// Employee array to hold employee data let employees = []; // Form submission handler to add a new employee document.getElementById('employeeForm').addEventListener('submit', function (e) { e.preventDefault(); const empId = document.getElementById('empId').value; const empName = document.getElementById('empName').value; const empEmail = document.getElementById('empEmail').value; const empDesignation = document.getElementById('empDesignation').value; const empProject = document.getElementById('empProject').value; const empSalary = document.getElementById('empSalary').value; const empDOJ = document.getElementById('empDOJ').value; const empLocation = document.getElementById('empLocation').value; // Create a new employee object const newEmployee = { id: empId, name: empName, email: empEmail, designation: empDesignation, project: empProject, salary: empSalary, doj: empDOJ, location: empLocation }; // Add employee to the array employees.push(newEmployee); // Reset form document.getElementById('employeeForm').reset(); // Refresh the employee table renderEmployeeTable(); }); // Function to render the employee table function renderEmployeeTable() { const employeeTableBody = document.querySelector('#employeeTable tbody'); employeeTableBody.innerHTML = ''; // Clear previous data // Loop through the employees array and insert rows employees.forEach((employee) => { const row = ` <tr> <td>${employee.id}</td> <td>${employee.name}</td> <td>${employee.email}</td> <td>${employee.designation}</td> <td>${employee.project}</td> <td>${employee.salary}</td> <td>${employee.doj}</td> <td>${employee.location}</td> </tr> `; employeeTableBody.innerHTML += row; }); }
Editor is loading...
Leave a Comment