开发者

Jquery Multiple check boxes with multiple pages

I have applied jquery in my jsp page.

I got mor开发者_高级运维e than thousnd records, i have to show all page by page,

when i am clicking the next button those pages came.

But my problem is i have to select multiple check boxes in all pages at the time i have to

send values of that check boxes, any one can u pls make answer for this.


The only realistic way of doing this is to attach a click event to all of your checkboxes. When they're clicked, fire off an AJAX request to the server to update the status of that particular checkbox. Store that state in the database or a session or whatever.

So for example:

$(function() {
  $(":checkbox").click(function() {
    $.get('/save/checkbox/url', {
      id: this.id,
      checked: this.checked
    });
  });
});

assuming:

<input type="checkbox" id="cb123">

Then when you finally want to use those results get the details from there.

Also when you populate the checkboxes on the page correctly check them or not based on the stored state.


Use AJAX to load the pages instead of doing a hard refresh. With that approach, every checkbox click can be recorded and stored in an Array which will persist because the page is not being refreshed.

To do this in jQuery, use something like:

$("#tableContainer").load("/data/page/2");

That would load the contents from the url, and inject it into an element with id "tableContainer".

Live events in jQuery will allow binding to all checkboxes (current and future):

$("#tableContainer input[type='checkbox']").live("click", function() {
    if($(this).is(':checked')) {
        checkedItems.add($(this).val());
    }
}

It's not complete as you'd have to remove an item from the Array if it was unchecked, and modify your servlet to send only part of the page that changes. But hope you got the idea.

jQuery has good documentation on ajax and live events.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜