5
I need it when the user writes to an input text, the checkbox of the respective table row should be marked, and if the user leaves the input text
blank again, checkbox is cleared. Follow code:
<table class="table table-striped" id="produtostab">
<thead>
<tr>
<th>Quantidade</th>
<th>Selecionar</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<input class="inputq1" name="inputquant" type="text" />
</td>
<td>
<input type="checkbox" name="checkboxvar">
</td>
</tr>
<tr>
<td>
<input class="inputq1" name="inputquant[]" type="text" />
</td>
<td>
<input type="checkbox" name="checkboxvar[]">
</td>
</tr>
</tbody>
</table>
<button id="add" class="btn btn-default">Adicionar</button>
As you can see, it will be a table with multiple lines, so it is no use for the user to write in a input
and mark all the checkbox
, it is necessary mark only those of the respective lines input
s are completed. I believe this should be done with Javascript, but as?
This is the PHP that creates HTML:
<?php
$conn = new mysqli('localhost', 'root', '', 'sindigrejinha') or die('Falha ao conectar-se com DB');
mysqli_query($conn, "SET NAMES 'UTF8'") or die("ERROR: " . mysqli_error($con));
$result = $conn -> query("select idProduto, Descricao from produto");
while ($row = $result -> fetch_assoc()) {
unset($idProduto, $Descricao);
$idProduto = $row['idProduto'];
$Descricao = $row['Descricao'];
echo '<tr>';
echo '<td>' . $Descricao . '</td>';
echo '<td><input name="inputquant[]" type="text" /></td>';
echo '<td><input type="checkbox" value="'. $idProduto .'" name="checkboxvar[]"></td>';
echo '</tr>';
}
?>
I wanted to remove the PHP code because the problem is pure JS/HTML, but as it has an answer that speaks of PHP, did not give...
– brasofilo