JSFiddle - React, Tailwind, and code Playground
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.0-2/css/all.min.css"
/>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<div class="container">
<table id="data_table">
<thead>
<tr>
<th>#</th>
<th>Date</th>
<th>From</th>
<th>To</th>
<th>Wage</th>
<th>Edit</th>
</tr>
</thead>
<tbody id="tbody">
<tr id="row">
<td id="serial"></td>
<td id="mydate"></td>
<td id="from"></td>
<td id="to"></td>
<td id="wage"></td>
<td id="edit">
<i class="far fa-edit" id="editrow" onclick="edit_row(no)"
><input type="button"
/></i>
<i
class="far fa-trash-alt"
id="deleterow"
onclick="delete_row(no)"
><input type="button"
/></i>
<i class="far fa-save"
><input
type="button"
id="saverow"
value="Save"
class="save"
onclick="save_row()"
/></i>
</td>
</tr>
</tbody>
</table>
<div class="hoursofwork">
<label>From</label>
<input type="time" placeholder="From" id="new_from" /> <label>To</label
><input type="time" placeholder="To" id="new_to" />
<button id="btn" type="button" onclick="add_row(); getmyDate()">
<i class="far fa-plus-square"></i>
</button>
</div>
</div>
<script src="app2.js"></script>
</body>
</html>
CSS
body {
margin: 0;
padding: 0;
display: flex;
justify-content: center;
width: 100vw;
height: 100vh;
}
.container {
position: relative;
width: 700px;
border: 2px solid black;
margin: 100px 0;
}
table {
width: 100%;
border-spacing: 0;
counter-reset: serial;
}
th,
td {
padding: 6px 12px;
border: 1px solid black;
}
th {
font-size: 1.5em;
font-family: Arial, Helvetica, sans-serif;
background: wheat;
}
th:nth-child(2) {
width: 200px;
}
#date {
width: 100px;
}
td {
text-align: center;
position: relative;
font-size: 1em;
font-family: fantasy;
}
td:first-child::before {
counter-increment: serial;
content: counter(serial);
}
#tbody #row {
display: none;
}
td:nth-child(5) {
padding: 0;
}
td input {
width: 90%;
font-size: 1em;
border: none;
}
.far {
cursor: pointer;
margin: 0 5px;
}
.fa-edit {
color: blue;
}
.fa-save {
display: none;
}
.fa-trash-alt {
color: red;
}
.employee,
.hoursofwork {
position: absolute;
bottom: 0;
left: 0;
width: 100%;
height: 55px;
background: green;
display: flex;
align-items: center;
justify-content: center;
flex-direction: row;
}
.employee input,
.hoursofwork input {
height: 25px;
width: 150px;
margin: 0 15px;
font-size: 1.3em;
}
#btn {
font-size: 2em;
text-align: center;
background: transparent;
color: white;
border: none;
cursor: pointer;
}
label {
font-size: 2em;
color: white;
font-family: fantasy;
}
JavaScript
var tbody = document.getElementById("tbody");
var btn = document.getElementById("btn");
//ADD ROWS//
function add_row() {
if (tbody.rows.length > 20) {
return;
}
new_from = document.getElementById("new_from").value;
new_to = document.getElementById("new_to").value;
var table = document.getElementById("data_table");
var table_len = table.rows.length - 1;
var row = (table.insertRow(table_len).outerHTML =
"<tr id='row" +
table_len +
"'><td id='serial" +
table_len +
"'></td><td id='mydate" +
table_len +
"'></td><td id='from" +
table_len +
"'>" +
new_from +
"</td><td id='to" +
table_len +
"'>" +
new_to +
"</td><td id='wage" +
table_len +
"'></td><td><i class='far fa-edit' id='editrow" +
table_len +
"' onclick='edit_row(" +
table_len +
")'></i> <i class= 'far fa-save' id='saverow" +
table_len +
"' onclick='save_row(" +
table_len +
")'></i><i class='far fa-trash-alt' onclick='delete_row(" +
table_len +
")'></i></td></tr>");
document.getElementById("new_from").value = "";
document.getElementById("new_to").value = "";
}
//EDIT ROWS//
function edit_row(no) {
from = document.getElementById("from" + no);
to = document.getElementById("to" + no);
document.getElementById("editrow" + no).style.display = "none";
document.getElementById("saverow" + no).style.display = "inline-block";
from_data = from.innerHTML;
to_data = to.innerHTML;
from.innerHTML =
"<input type='text' id='from_text" + no + "' value='" + from_data + "'>";
to.innerHTML =
"<input type='text' id='to_text" + no + "' value='" + to_data + "'>";
}
//SAVE ROWS//
function save_row(no) {
var from_val = document.getElementById("from_text" + no).value;
var to_val = document.getElementById("to_text" + no).value;
document.getElementById("from" + no).innerHTML = from_val;
document.getElementById("to" + no).innerHTML = to_val;
...