I have a table with a check box which allows to edit the columns in the chosen row. Whenever I click the check box, a dialog pop's out, as it should be. The problem begins when I dynamically change the page content with Ajax (When I change the page of the table). Whenever I click on the 'next' button (to get the next rows of the table), the content changes dynamically and the dialog doesn't pop out when I click on the edit check box. I tried various ways to handle the change but it seems to me that I can't get it right.
Here is the Next button code:
$('#Next').click(function(){
if(Number($('#Next').attr('n'))+1 >= Number($('#Next').attr('tn'))){
$('#Next').removeAttr('class');
$('#Next').attr('class','next disabled');
}
var tmp = Number($('#Next').attr('n'));
$('#Next').removeAttr('n');
$('#Next').attr('n',(tmp+1).toString());
$.get("receive.php",{Page: $('#Next').attr('n')}).done(function(data){
$('tbody').html(data);
$('#Previous').removeAttr('class');
$('#Previous').attr('class','previous');
$.PutRating();
});
});
The data I receive from the php function is the new table content, but then, I can't use the edit check box. Here is the code for it:
$('input.cb').on('change',function(){
$('input.cb').not(this).prop('checked',false);
BootstrapDialog.show({
title: 'Choose Option',
message: 'Select an option for: <strong>'+$(this).attr('n')+'</strong>. Be careful!',
draggable: true,
type: 'type-warning',
data:{
'name': $(this).attr('n')
},
buttons: [{
label: 'Edit',
icon: 'glyphicon glyphicon-pencil',
cssClass: 'btn-warning',
action: function(dialogItself){
dialogItself.close();
$('#ShowForm').trigger('click');
$('#ShowForm').hide();
$('#Add').text('Save');
$('#Add').attr('class','btn btn-success pull-right');
$('#Close').show();
$.post('receive.php',{GetRow: 'true',Name: dialogItself.getData('name')}).done(function(data){
var values = data.split(':');
$('#Type').val(values[0]);
$('#Name').val(values[1]);
$('#Hobby').val(values[2]);
$('#Favorite_color').val(values[3]);
$('#Favorite_food').val(values[4]);
$('#Notes').val(values[5]);
});
}
}, {
icon: 'glyphicon glyphicon-trash',
label: 'Delete',
cssClass: 'btn-danger',
action: function(){
}
}]
});
});
input.cb is the check box input. I tried the .on function, but It didn't work, I guess I didn't understand it.