1
The image is an example of what I want. When is checkado
to checkbox
of verificaçãoAntiga
, makes the Text
of Versao Nova
active. He does it at first but not at others. Someone can help me?
<?php
include('conect.php');
$result = mysqli_query($conn,"SELECT * FROM `op` WHERE `type` = 2 ;");
echo "<table class='table table-striped table-hover'id='datatables-example'>
<tr>
<td class='pure-table'><b>Title 1</b></td>
<td class='pure-table'><b>Title 2</b></td>
<td class='pure-table'><b>Check 1</b></td>
<td class='pure-table'><b>Title 3</b></td>
<td class='pure-table'><b>VCheck 2</b></td>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tbody data-link='row' class='rowlink'>
<tr>
<td>' . $row['Op'] . '</td>
<td> <input type='text' name='T2' class='form-control'></td>
<td style='text-align:center;'> <input type='checkbox' name='C1' id='C1' ></td>
<td> <input type='text' name='T3' id='T3' class='form-control' disabled ></td>
<td style='text-align:center;'> <input type='checkbox' name='C2'></td>
</tr>
</tbody>
}
</table>";
mysqli_close($conn);
?>
<script language ="JavaScript">
document.getElementById('C1').onchange = function() {
document.getElementById('T3').disabled = !this.checked;
};
If I haven’t been very explicit in my intentions, please ask. Thank you.
Are you using Jquery or just pure Javascript ? The problem is that all checks have the same id, so getElement returns the first element of the DOM tree, you need to generate unique ids and pass this to the function
– Lucas Queiroz Ribeiro
The simplest solution is to place the JS inside the loop, and dynamically generate the Ids. To avoid repeating JS, you could put a data-attribute in the checkboxes indicating the ID of the corresponding text, or simply use selectors to catch the neighboring textbox (in this case, subject to problems if you restructure the HTML). Then you could use a JS only for all fields.
– Bacco