fix checked box

This commit is contained in:
KhatamNugraha
2024-04-19 18:26:43 +07:00
parent 9c25832686
commit b81221d818

View File

@ -445,32 +445,61 @@
var value = $(this).val();
// alert($(this).index());
if ($(this).is(':checked')) {
// Checkbox is checked, add value to the array
selectedValues.push(value);
} else {
var value = $(this).val();
var allvall = $("input[name=acc_no]").val();
var arrVal = allvall.split(',');
$.each(arrVal, function(index, val){
if (val != value) {
arrVal.splice(index, 1);
}
selectedValues.push(arrVal);
// let index = array.indexOf(elementToRemove);
});
// Checkbox is unchecked, remove value from the array
var index = selectedValues.indexOf(value);
if (index !== -1) {
selectedValues.splice(index, 1);
}
}
// Display the selected values (just for demonstration)
$('.selected-values').val(selectedValues.join(','));
$('input[name=acc_no]').val(selectedValues);
});
var arr = [];
$("#selectAll").on('click', function() {
$('.exportPdf').show();
$("input[type=checkbox]").prop('checked', $(this).prop('checked'));
$.each($("input[name='account_number']:checked"), function() {
arr.push($(this).val());
$("input[name=acc_no]").val(arr)
});
if ( $(this).prop('checked')) {
arr.splice(0, arr.length);
$("input[type=checkbox]").prop('checked', $(this).prop('checked'));
$.each($("input[name='account_number']:checked"), function() {
arr.push($(this).val());
$("input[name=acc_no]").val(arr)
});
} else {
arr.splice(0, arr.length);
$("input[type=checkbox]").prop('checked', false);
$.each($("input[name='account_number']"), function() {
// arr.push($(this).val());
$("input[name=acc_no]").val('')
});
}
});