2
I’m not able to pass the data from a table I have on a page . php to a modal window that shows this data, which would be for editing.
The only thing I can pass is the id, which in turn can be used to perform the update in the database without problems if I fill in the inputs.
I would like to know how to pass this table data to Texts input by Javascript, or by other means if possible.
Trigger to open the modal:
<i class="fas fa-edit ml-1" title="Editar" data-toggle="modal" data-target="#modalCliente" id="btnEditar" onclick="editar(<?= $cliente->id ?>)"></i>
Inputs from modal window:
<div class="col-md-6">
<label for="nomeCliente">Nome do Cliente</label>
<input class="form-control" type="text" id="nomeCliente" name="nomeCliente">
</div>
<div class="col-md-3">
<label for="cpfCliente">CPF</label>
<input class="form-control" type="text" id="cpfCliente" name="cpfCliente" onkeydown="javascript: fMasc( this, mCPF );">
</div>
<div class="col-md-3">
<label for="cnpjCliente">CNPJ</label>
<input class="form-control" type="text" id="cnpjCliente" name="cnpjCliente" onkeydown="javascript: fMasc( this, mCNPJ );">
</div>
Table listing the data:
<table class="table table-sm table-bordered table-striped" id="tabelaClientes">
<thead>
<tr>
<th>Nome</th>
<th>CPF</th>
<th>CNPJ</th>
<th>ID</th>
<th>Opções</th>
</tr>
</thead>
<tbody>
<? foreach ($listaCliente as $indice => $cliente) { ?>
<tr><td>
<?= $cliente->nome ?>
</td>
<td>
<?= $cliente->cpf ?>
</td>
<td>
<?= $cliente->cnpj?>
</td>
<td>
<?= $cliente->id ?>
</td>
<td class="opcoes">
<i class="fas fa-edit ml-1" title="Editar" data-toggle="modal" data-target="#modalCliente" id="btnEditar" onclick="editar(<?= $cliente->id ?>)"></i>
<i class="fas fa-trash-alt ml-1" title="Excluir" data-toggle="modal" data-target="#modalExcluir" ></i>
</td>
</tr>
<? } ?>
</tbody>
It was exactly what I wanted, the problem above was solved only with this, which was breaking my head. Now another "problem" that arises, is that table data are not all that exist in the BD client table, there are other attributes like email, phone, etc. For this, I can use the edit() function to access the BD and rescue this data, through the ID ?
– thiaguera94
Yeah, then you’d have to use Ajax.
– Sam