So I have a checkbox and an "input number" and I want to enable/disable that input when check/uncheck the checkbox with jquery!!
Here is the code:
$(document).ready(function() {
$("#criar").click(function() {
$('input[name^="quant"]').each(function() {
$(this).attr('disabled', 'disabled');
});
$('#myform').change(function(){
var i=0;
$('input[name^="tipo"]').each(function() {
if($(this).prop('checked')){
$('#textnumber').eq(i).prop('disabled', false);
}else{
$('#textnumber').eq(i).prop('disabled',true);
}
i++;
});
});
});
});
And the html code:
<input type="checkbox" name="tipo[]" id="tipo">
<input type="number" name="quant[]" min="1" max="50" id="textnumber[]">
This is working but only with the first checkbox and input as you can see here
$('#criar'). also depending on what you want to do you could create a class for all the checkboxes and then useeachto loop over them and use$(this)to capture checkbox you're actually clicking on