I need when the user types in an input text, the checkbox of the respective table line should be checked, and if the user leaves the input text
again in blank, the checkbox unchecks. Here is the 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 to mark all checkbox
, it is necessary to < s are filled in . I believe this should be done with JavaScript, but how?
This is 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>';
}
?>