In my website, I have a page where there is rows from my database, and 4 columns. The first one (0) is titles, and the fourth one (3) is only checkboxes. I also have a button where I can check all checkboxes (checkAll).
My problem is, when I click on the validate button of my page, I want to get titles associated with checked checkboxes. The constraint is I can't make a onchange function for each checkbox, so a good solution - according to me - is to get every titles in a variable. But how I can get the correct rows in order to have titles ? The commentary lines, if we uncomment them, works but it always print me the first title of the first row. Titles are on another table, let's call it tableStock.
$("#checkAll").on('change', function () {
var checkbox;
var idCheckBox;
var length = $('[id^=chk_acc_]').length;
for( var i = 0; i < length; i++ ){
tr = $(this).closest('tr');
checkbox = $('[id^=chk_acc_]').get(i);
// id= $(this).closest('tr').attr('id');
idCheckBox = checkbox.getAttribute('id');
if( checkbox.getAttribute('style') != "display: none;"){
if($(this).attr('checked') == 'checked'){
$('#' + idCheckBox).prop('checked', true);
// alert($('td:eq(0)', id).text());
}
else{
$('#' + idCheckBox).prop('checked', false);
}
}
}
});
Can someone help me please ?
Aucun commentaire:
Enregistrer un commentaire