I have created multiple checkboxes in table dynamically. Each checkbox has a hidden field with the column id which is to be send to the server but it only sends the value of the first checkbox if its clicked and does not iterate over the whole table. I have tried to look for a solution but its still producing the same result. Here is the code snippet:
var tdCheck = $('<td>').html('').attr({
'id': 'check'
}).appendTo(trbody);
var checkfield = $('<input>').html('').attr({
'type': 'checkbox',
'id': 'select',
'value': entered[i].id
}).addClass('form-control').appendTo(tdCheck);
var br = $('<br>').html('').appendTo(tdCheck);
var hiddenfield = $('<input>').html('').attr({
'id': 'columnid',
'type': 'hidden',
'value': entered[i].id
}).appendTo(tdCheck);
Code for ajax call
$('#accept').click(function() {
$(':checkbox:checked').each(function(i) {
var columnId = [];
columnId[i] = $('#columnid').val();
JSON.stringify(columnId[i]);
$.ajax({
type: 'POST',
url: '/ProductApproval/handlers/ProductApproval.ashx',
data: {
Action: "ApprovalStatus",
ColumnId: columnId[i],
flag: 1 //status for accept
}
});
});
});
Aucun commentaire:
Enregistrer un commentaire