1
I managed to create a javascript creating a new element from the id of the name, but I also want to add the value and date input elements, as I do?
I tried to copy like I did with the name:
var textoValor = document.getElementById('novoValor')
tr.textContent = textoValor.value;
I would also like to know how to reset the table
var novoNome = document.getElementById('novoNome');
var novoValor = document.getElementById('novoValor');
var novaData = document.getElementById('novaData');
btnNovoCliente = document.getElementById('btnNovoCliente');
var tbody = document.getElementsByTagName("tbody")[0];
function adc() {
document.getElementById("btnNovoCliente").addEventListener("click", function(){
var cliente = document.getElementById('tbody');
var textoNome = document.getElementById('novoNome');
var tr = document.createElement('tr');
tr.textContent = textoNome.value;
cliente.appendChild(tr);
});
}
window.addEventListener("load", adc);
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html {
font-family: monospace;
font-size: 16px;
background-color: rgba(10, 5, 9, 0.233);
}
body {
width: 90%;
height: 90%;
display: flex;
flex-direction: column;
font-family: monospace;
}
.left {
background-color: gray;
width: 350px;
height: 270px;
padding: 15px 30px;
margin: 30px 30px;
}
.left form .formulario input {
width: 275px;
height: 30px;
margin: 6px;
padding: 10px;
}
.left form .btn {
margin-top: 15px;
display: flex;
flex-direction: row;
margin-left: -5px;
}
.left form .btn input {
margin: 10px;
width: 80px;
height: 30px;
}
#btnResetar {
background-color: rgb(187, 111, 111);
font-weight: bolder;
color: white;
}
.right {
display: flex;
flex-direction: column;
width: 1440px;
height: 900px;
}
.right table {
border: 1px solid white;
margin-left: 60px;
}
.right table thead tr th {
border: 1px solid white;
outline: solid white;
}
.right table thead tr th {
margin-right: 100px;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>MyClients</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
<div class="left">
<form action="#">
<div class="formulario">
<div class="nome">
<label for="lNome">Nome:</label>
</div>
<div class="novoNome">
<input type="text" id="novoNome">
</div>
<div class="valor">
<label for="lValor">Valor:</label>
</div>
<div class="novoValor">
<input type="text" id="novoValor">
</div>
<div class="data">
<label for="lData">Data:</label>
</div>
<div class="novaData">
<input type="text" id="novaData">
</div>
</div>
<div class="btn">
<input type="button" id=btnNovoCliente value="Criar">
<input type="button" id=btnNovoCancelar value="Cancelar">
<input type="button" id=btnResetar value="Resetar">
</div>
</form>
</div>
<div class="right">
<table>
<thead>
<tr>
<th>Nome</th>
<th>Valor</th>
<th>Data</th>
</tr>
</thead>
<tbody id="tbody">
</tbody>
</table>
</div>
</div>
</body>
</html>