lundi 27 février 2017

How to post id on checkbox in Jquery?

I want to make a simple pagination page. This is regarding delete function. I have a checkbox that user can choose to delete a row. May I know how to post/get the id of the row if user click on next link? In my case, the id will be duplicate if user click on the checkbox. Below are my codes,

jQuery

var cbNew = [],
cbAdd = [];

function addId(checkBox){
    cbAdd = cbAdd.concat(checkBox);
    console.log(cbAdd);
}

$(document).on("click", ".checkBox", function(){
    var cb = [];
    $('.checkBox:checked').each(function(){
        cb.push($(this).val());
    });

    if(cb.length > 0) { 
        addId(cb);
        $('#delete').fadeIn(); 
    } else {
        $('#delete').fadeOut();
    }
});

//Link on Next Page
$(".nextPage").click(getFunct);

function getFunct(e){
    e.preventDefault();
    var url = $(this).attr('href'),
    row = getURLParameter(url, 'startrow'),
    cbNew = cbNew;
    getParam(row,url);
}

function getParam(param1,param2){
    $.ajax({
        type: "POST",
        url: url,
        data: 
        {
            row : param1,
            url : param2,
            cbNew : cbNew
        }
    }).done(function(data){
        $('#result').html(data);
        addId(cbNew);
    });
}

This is the output if I click on multiple checkbox on same page console.log(cbAdd);

["25", "25", "26", "25", "26", "27"]

If I click one checkbox on page 1 and one checkbox on page 2, it get the id correcltly

["25", "59"]




Aucun commentaire:

Enregistrer un commentaire