0

I'm running into a issue where the checkbox of input elements are not correctly returning checked or not checked status. 2 input checkbox elements are dynamically called via ajax with default checked and updated in div element using innerHTML, when I uncheck the same checkbox element on a form and submit, it is still showing me 2 checked input elements when there are none checked, it is not showing correctly the current selection of the checkbox after unchecked.

Here is my jquery code
let checkboxes = document.querySelectorAll('input[name="checkboxele"]:checked');

From my code values array should have nothing because I have unchecked 2 checkbox elements, but when I print the values array I see there are 2 checkbox elements, probably from the default selection.

Sid Ahmed
  • 11
  • 5
  • 1
    Can you show your html code too. – Gopi krishna Feb 27 '22 at 06:30
  • let checkboxes = document.querySelectorAll('input[name="checkboxele"]:checked'); let values = []; checkboxes.forEach((checkbox) => { if (checkbox.checked === true) { values.push(checkbox.value); } }); – Sid Ahmed Feb 27 '22 at 06:32

0 Answers0