Greetings I have a problem I am trying to enable Inputs as you select checkbox, the problem is that they are checkboxes shown by a while
which comes from the database. Below I show the code.
<div class="campo clearfix">
<label for="herram" id="herra">Selecionar herramientas:</label><br/>
<?php
try {
$sql = "SELECT * FROM herramienta";
$res_herram = $conn->query($sql);
$total_h = $res_herram->num_rows;
$i = 0;
while ($herram = $res_herram->fetch_assoc()) {
echo '<div class="contenido_dia">';
echo '<input type="checkbox" id='"checkh" . $herram['id_herra'] . ' name="herram[]" value=' . $herram['id_herra'] . '> ' . $herram['nom_herra'] . " " ;
echo '<input type="number" min="0" max="5" disabled="disabled" id='"canth". $herram['id_herra'] . ' size="1" name="herram_cant[]" placeholder="0">' . '<br/>';
echo '</div>';
$i++;
}
} catch (Exception $error) {
echo "Error:" . $error->getMessage();
}
?>
</div>
I was trying with this javascript but I think this is very bad
for (var i = 0; i < 9; i++) {
$("#checkh" + i).change(function(){
var comentario = $( '#canth' +i, $(this).parents ('div'));
if( $(this.checked)){
comentario.removeAttr('disabled');
} else {
comentario.attr('disabled', true);
}
});
}