diff --git a/Resources/views/pages/index.blade.php b/Resources/views/pages/index.blade.php index 687fdf6..cdf404a 100644 --- a/Resources/views/pages/index.blade.php +++ b/Resources/views/pages/index.blade.php @@ -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('') + }); + } + });