So far, I have the following code:
I need the dropdowns to save, but can't work out how.
Can anyone help?
HTML:
<!DOCTYPE html>
<html>
<head>
<title>Company HR</title>
<style>
h1 {
font-family: verdana;
text-align: center;
font-size: 50px;
}
table,
th,
td,
select {
border: 1px solid black;
border-collapse: collapse;
font-family: Verdana;
font-size: 20px;
}
.centre {
margin-left: auto;
margin-right: auto;
}
</style>
</head>
<body>
<h1>Company Employee List</h1>
<table class="centre" id="employee-table">
<thead>
<tr>
<th>Name</th>
<th>Role</th>
<th>Active</th>
<th>Assigned</th>
</tr>
</thead>
<tbody></tbody>
</table>
<script>
const employees = [
{ name: "John Doe", role: "Co-CEO/Editor", active: "Yes", assigned: "n/a" },
{ name: "Jane Doe", role: "CEO", active: "Yes", assigned: "n/a" },
{ name: "Bob Doe", role: "Co-CEO/Animator", active: "No", assigned: "No" },
{ name: "Janet Doe", role: "Co-CEO", active: "No", assigned: "No" },
];
const table = document.getElementById("employee-table").querySelector("tbody");
function createOption(value, selected) {
const option = document.createElement("option");
option.value = value;
option.textContent = value;
if (value === selected) {
option.selected = true;
}
return option;
}
employees.forEach((employee) => {
const row = table.insertRow();
const { name, role, active, assigned } = employee;
row.insertCell().textContent = name;
row.insertCell().textContent = role;
const activeSelect = document.createElement("select");
activeSelect.appendChild(createOption("Yes", active));
activeSelect.appendChild(createOption("No", active));
activeSelect.appendChild(createOption("n/a", active));
row.insertCell().appendChild(activeSelect);
const assignedSelect = document.createElement("select");
assignedSelect.appendChild(createOption("Yes", assigned));
assignedSelect.appendChild(createOption("No", assigned));
assignedSelect.appendChild(createOption("n/a", assigned));
row.insertCell().appendChild(assignedSelect);
});
</script>
</body>
</html>
I need the dropdowns to save, but can't work out how.
Can anyone help?