Crazylife's avatar

How to persist checkbox checked state after div content reload?

I have a pagination for div which during go to another pages the previous checkbox state will lost.

 var id;
   $("#list :checkbox").each(function(e){
   id = this.id;
   console.log(this.value);
   });

Code above can get all the value in a div tag if without button click.

If i use the code below, it only shows the data for the page 1.

$("#select-all").click(function(e) {

var id;
   $("#list :checkbox").each(function(e){
   id = this.id;
   console.log(this.value);
   });
                });

I am not using datatable to display data, i am using div tag to display 6 items per page, but i always get the value only where the current page is active. Any solution to solve the issue?

0 likes
4 replies
jlrdw's avatar

You have to check the database and see if a 0 or 1 is stored, and code it checked or not checked, a discussion on checkbox handling was recently discussed here.

IsaacBen's avatar

Not sure I understand. You have multiple pages and you want to maintain checkbox state across pages? I would avoid that and just render all at the same page. If you change the DOM then the checkbox state would get erased, unless you store them in the local storage or something, but that's ugly.

Crazylife's avatar

Yes, this is what i am looking for. But if i render all at the same page it will be a lot of data. I am displaying image and checkbox in gridview with laravel paginatior.

Please or to participate in this conversation.