The modal shows data that is retrieved by a query and I am filling it with a for cycle.
With several tests that I did I could get true or false which is the value of the checkbox but what does not change is the state of the input to enable or disable according to the case that is my main problem.
In this function my problem is centered with the tests that I did not manage to solve the prob. enableDisable (option)
<div id="modalPay" class="modal fade modal-child" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title">Modal title</h4>
</div>
<div class="modal-body">
<form action="" method="post" class="form-horizontal">
<div class="row">
<div class="col-xs-5 col-sm-3">
<h4><strong>Nombre de cliente:</strong></h4>
</div>
<div class="col-xs-7 col-sm-9" id="clientName">
</div>
</div>
<hr/>
<div class="row">
<table class="table table-hover">
<thead>
<tr>
<th class="text-center">Fecha compra</th>
<th class="text-center">Monto total</th>
<th class="text-center">A cuenta</th>
<th class="text-center">Saldo</th>
<th class="text-center">Habilitar pago</th>
<th class="text-center">Monto a pagar</th>
<th class="text-center">Detalles</th>
</tr>
</thead>
<tbody id="myFormPay">
</tbody>
</table>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cerrar</button>
<button type="button" id="btnSavePay" class="btn btn-primary">Guardar</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<script>
$('#modalPay').modal('show');
$('#modalPay').find('.modal-title').text('Realizar pago');
$('#myFormPay').attr('action', '<?php echo base_url() ?>pagov/addPay');
$.ajax({
type: 'ajax',
method: 'post',
async: false,
url: '<?php echo base_url() ?>pagov/makePay',
data: {id: id},
dataType: 'json',
success: function (data) {
var html = '';
var html1 = '';
html1 += '<h4><strong>'+data[0].ven_cliente+'</strong></h4>';
$('#clientName').html(html1);
var i;
for(i=0;i<data.length;i++){
html += '<tr>'+
'<td class="col-sm-1 col-md-1 text-center"><strong>'+data[i].ven_fecha+'</strong></td>'+
'<td class="col-sm-1 col-md-1 text-center"><strong>'+data[i].ven_total+'</strong></td>'+
'<td class="col-sm-1 col-md-1 text-center"><strong>'+data[i].pv_monto+'</strong></td>'+
'<td class="col-sm-1 col-md-1 text-center"><strong>'+(data[i].ven_total - data[i].pv_monto)+'</strong></td>'+
'<td class="col-sm-1 col-md-1 text-center">'+
'<input type="checkbox" id="checkedItem'+i+'" onchange="enableDisable(this.id)">'+
'</td>'+
'<td class="col-sm-1 col-md-1" align="center">'+
'<input id="payItem'+i+'" type="number" class="form-control" min="0" max="100000" style="width:85px" maxlength="6" disabled="disabled">'+
'</td>'+
'<td class="col-sm-1 col-md-1" align="center">'+
'<a href="javascript:;" class="btn btn-default glyphicon glyphicon-list vent-detail" data="' + data[i].ven_id + '"data-toggle="tooltip" data-placement="right" title="Detalle de venta"/>' +
'<a href="javascript:;" class="btn btn-danger glyphicon glyphicon-list-alt item-pay" data="' + data[i].ven_id + '"data-toggle="tooltip" data-placement="right" title="Historial de pagos"/>' +
'</td>' +
'</tr>' ;
}
$('#myFormPay').html(html);
}
});
});
function enableDisable(option){
//en esta
var chk = document.getElementById(option).value;
//var chk = option.
if(chk === 'on'){
$('#payItem0').attr('disabled',!this.checked);
alert(chk);
}
}
</script>