1
I have a table created in array, and the modal button opens a table for selection of units of weight / measure, but when the selection is captured fills the whole table as in the photo below. How do I fill only the line ?
Table structure opened by clicking on the modal
<table class='table table-bordered'>
<thead>
<tr>
<th> Unidade </th>
<th> Descrição </th>
</tr>
</thead>
<tbody>
<?php
include ("conn.php");
$result = "SELECT * FROM cadunid ORDER BY descricao";
$resultado = mysqli_query($conn, $result);
while($row = mysqli_fetch_assoc($resultado)) {
echo "<tr class='btn-default'>";
echo "<td class='get-value'>". $row['codigo'] ."</td>";
echo "<td class='get-value-codigo'>". $row['descricao'] ."</td>";
echo "</tr>";
}
?>
</tbody>
</table>
table structure shown in the image above
<table class="table table-bordered"><!-- Iniciando a Tabela -->
<thead>
<tr><!-- Início dos Títulos da Tabela / Cabeçalho -->
<th><button type="button" class="" data-toggle="modal" data-target="#myModal">Unidade >> </button></th>
<th>Preço Custo</th>
<th>Preço Venda</th>
<th>Peso Bruto</th>
<th>Peso Liquido</th>
<th>Qtd. Emb.</th>
</tr><!-- Fim dos Títulos da Tabela / Cabeçalho -->
</thead>
<tbody id='prprod'><!-- Início do Corpo da tabela / Quantidade de linhas e colunas -->
<?php for($i = 0; $i <= 5; $i++){ //coloquei este valor para testar ?>
<tr>
<input type="hidden" maxlength="6" name="recnum[]" style="border:none; width:100%; background-color: transparent;">
<td><input type='text' name="unidad[]" class="unidade-input" style="border:none; width:100%; background-color: transparent;">
<td><input type="text" maxlength="" name="preco_custo[]" placeholder="" style="border:none; width:100%; background-color: transparent;"></td>
<td><input type="text" maxlength="" name="preco_venda[]" placeholder="" style="border:none; width:100%; background-color: transparent;"></td>
<td><input type="text" maxlength="" name="peso_bruto[]" placeholder="" style="border:none; width:100%; background-color: transparent;"></td>
<td><input type="text" maxlength="" name="peso_liquido[]" placeholder="" style="border:none; width:100%; background-color: transparent;"></td>
<td><input type="text" maxlength="" name="qtde_embalagem[]" placeholder="" style="border:none; width:100%; background-color: transparent;"></td>
</tr>
<?php } ?>
</tbody><!-- Fim do Corpo da tabela / Quantidade de linhas e colunas -->
</table><!-- Finalizando a Tabela -->
script used to capture user-selected drive
<script>
$(document).on('click', '.get-value', function() {
var value = $(this).text();
$('.close').trigger('click');
$('.unidade-input', "tr").find.val(value); /* tentei desta forma porém continua preenchendo toda tabela */
});
$(document).on('click', '.get-value-codigo', function() {
var value = $(this).siblings('.get-value').text();
$('.close').trigger('click');
$('.unidade-input').val(value);
});
</script>
so much putting ID’s on the lines... then when filling picks up the tr with x ID
– Matheus Lopes Marques
there is no way to put id in a loop for, it would have to be class, because ID is unique from an element already class could be defined for all elements of the array, so it is set with class
– user92870
loop so I know it’s increasing... uses the loop variable itself as ID, but if Voce says n then n uses :D
– Matheus Lopes Marques
I have tried to test with ID, and it does not capture the user selection, with class yes, because class is used for all elements covered in while, and id would make all elements brought in the modal table have the same id, IE, this is impossible, bring a while with ID instead of class, you know? My problem is to bring only one line and not in capturing the die
– user92870