0
Hello, I’m studying and I’m having a difficulty with that, I have a table with some data that comes from the Postgre bank, I generated a checkbox to get the data of the row of the requested table to be able to accept the work, however independent of the checkbox line it only takes the data of the first.
When I click on the checkbox of the last row it does not return the data of the corresponding row.
What could I be doing wrong ?
var linha;
function deletar() {
var myTD = document.getElementById('ordersTable').getElementsByTagName('tr')[linha];
myTD.parentNode.removeChild(myTD);
}
function selecionar(name) {
linha = document.forms["form"].elements[name].value;
var status = document.forms["form"].elements[name].checked;
popularInputs(linha, status);
}
function popularInputs(td, status) {
if (status === false) {
limpeza();
} else {
document.forms["form"].elements["nome"].value = document.getElementById("nome" + td).innerHTML;
document.forms["form"].elements["trabalhos"].value = document.getElementById("trabalhos" + td).innerHTML;
document.forms["form"].elements["celular"].value = document.getElementById("celular" + td).innerHTML;
document.forms["form"].elements["email"].value = document.getElementById("email" + td).innerHTML;
}
}
function limpeza() {
document.forms["form"].elements["nome"].value = "";
document.forms["form"].elements["trabalhos"].value = "";
document.forms["form"].elements["email"].value = "";
document.forms["form"].elements["celular"].value = "";
}
HTML
<form name="form" method="post">
{% csrf_token %}
<table id="ordersTable" summary="Tabela de dados de uma agenda" class="table">
<thead class="thead-dark">
<th><input type="checkbox" id="marcar" name="marcar" /></th>
<th scope="col">Nome do Cliente </th>
<th scope="col">Email do Cliente </th>
<th scope="col">Telefone do Cliente </th>
<th scope="col">Dia para contato </th>
<th scope="col">Tipo de trabalhos </th>
<th scope="col">Mensagem </th>
</thead>
{% for value in List %}
<tbody>
<tr>
<td><input type="checkbox" name="marcar0"
onclick="return selecionar(this.name);" /></td>
<td id="nome" class="dark-row" scope="row">{{value.nome}}</th>
<td id="email" class="light-row">{{value.email}}</td>
<td id="celular" class="light-row">{{value.celular}}</td>
<td class="light-row">{{value.data}}</td>
<td id="trabalhos" class="light-row">{{value.trabalhos}}</td>
<td class="light-row">{{value.mensagem}}</td>
</tr>
</tbody>
{% endfor %}
</table>
<h2>Aceitar trabalho</h2>
<input type="text" name="nome" placeholder="Nome" />
<input type="text" name="trabalhos" placeholder="Trabalho" />
<input type="email" name="email" placeholder="Email" />
<input type="tel" name="celular" placeholder="Telefone" />
<input type="submit" name="cadastrar" value="Aceitar" />
<input type="submit" name="remover" value="Remover" onclick="return deletar();" />
</form>
Thank you for your attention.
Thank you for the comment, if I put it this way it does not take any line... The part of the name="marker0", it is from another code that she makes the lines manually and puts id on each of them, ai works, in my case the lines appear according to the amount of data you have in the database... and I do not know if you can put ID if it is like this, I tried to put a variable {{value.id_client}}that you have in my database to try to simulate but also could not.
– Matheus Canton