开发者

Store checked values from ajax pages

开发者 https://www.devze.com 2023-03-08 08:33 出处:网络
Mostly i have 28 items, i used pagination and display in 3pages using Ajax each pag开发者_如何转开发e have 10 items, whatever i selected in check box it should displayvalues at bottom ,every thing is

Mostly i have 28 items, i used pagination and display in 3pages using Ajax each pag开发者_如何转开发e have 10 items, whatever i selected in check box it should display values at bottom ,every thing is OK right now, but my problem is when i select items in second page the previous list is disappearing , when i return back to fist page it is not showing previously selected items .

iam not getting how to do this please help thanks i used this jquery code to get checked values

function showValues() {
    var page = $("#pagedis").val();
    var fields = $(":input").serializeArray();
    $("#results_" + page).empty();
    jQuery.each(fields, function(i, field) {
        $("#results_" + page).append(field.value + "<br> ");
    });
}

i need the action like gmail if we select 3 items in one page ,4 items in 2nd page ,when i come back the checked value will never chage


  1. do your checkboxes all have the same name? If not, name them all the same.
  2. make sure each checkbox has a unique value attribute
  3. attach a handler to keep track of the checkboxes checked in an array

:

// global variable somewhere
var checkedBoxes = new Array();

$('input[name=theNameYouDefinedAbove]').click(function(event){
    checkedBoxes[$(this).val()] = $(this).is(':checked');
});
  1. Now, when you paginate, just do this

:

$('input[name=theNameYouDefinedAbove]').each(function(index, checkbox){
    if (checkedBoxes[$(checkbox).val()]) {
        // NOTE: choose ONLY ONE!

        // for jQuery 1.6+
        $(checkbox).prop('checked', true);
        // for all jQuery
        $(checkbox).attr('checked', 'checked');
    }
});
0

精彩评论

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