0

I am using dataTable.jquery and I have a table that has several pages. Each row has a checkbox, and there is a checkbox for Select All. Now, I have some code that executes on checkbox.change, but it works on first page only. If I go to any other pages, it just checks the checkbox and does nothing. When I return to a page, all the checkboxes I've checked previously are unchecked.

Here is the code:

$('.bulk-checkbox').change(function(){
  alert("checkbox changed");
  if(this.checked) {
    alert("checkbox checked");
  }
  else {
    alert("checkbox NOT checked"); 
    } 
});
ivanacorovic
  • 2,125
  • 3
  • 23
  • 35
  • 1
    try this, before that don't forgot to add jquery.min.js $(document).on('change','.bulk-checkbox'.function(){ alert("checkbox changed"); if(this.checked) { alert("checkbox checked"); } else { alert("checkbox NOT checked"); } }); jquery –  Sep 15 '15 at 07:21
  • 1
    Well, sure.. that's pretty much the standard behaviour. How are the boxes displayed to begin with? Hardcoded HTML? Consider displaying the boxes dynamically with PHP and save the checked ones in a $_SESSION variable type array. When you then loop through the boxes you check whether the actual box is in the array to display it as checked. – entiendoNull Sep 15 '15 at 07:22

0 Answers0