Well in the example I posted I can disable input valor1
, vendedor1
and supervisor1
by checking the recalcular1
option.
The problem is that I have a form with several input, and to avoid a very large code I wanted to make the jqeury identify the number of checkbox
and disable only the inputs of the same number.
Example:
The recalcular1
disables the valor1
, vendedor1
, and supervisor1
fields.
The recalcular2
disables the valor2
, vendedor2
, and supervisor2
fields.
Does anyone know a practical way to do this?
$(document).ready(function() {
$("#recalcular1").on("blur change", function() {
// Verifica se exibe
if ($("#recalcular1").is(':checked')) {
$("#valor1").prop('disabled', true);
$("#vendedor1").prop('disabled', true);
$("#supervisor1").prop('disabled', true);
} else {
$("#valor1").prop('disabled', false);
$("#vendedor1").prop('disabled', false);
$("#supervisor1").prop('disabled', false);
}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type='checkbox' id='recalcular1' class='checkbox' name='recalcular1'>
<div>
<input type='text' id='valor1' name='valor1'>
<input type='text' id='vendedor1' name='vendedor1'>
<input type='text' id='supervisor1' name='supervisor1'>
<!-- Não pode ficar desabilitado -->
<input type='text' id='qtd1' name='qtd1'>
</div>
<br><br>
<input type='checkbox' id='recalcular2' class='checkbox' name='recalcular2'>
<div>
<input type='text' id='valor2' name='valor2'>
<input type='text' id='vendedor2' name='vendedor2'>
<input type='text' id='supervisor2' name='supervisor2'>
<!-- Não pode ficar desabilitado -->
<input type='text' id='qtd2' name='qtd2'>
</div>