I would like to count the checkboxes that are checked and display the count in the Div.
Here is my HTML :
<form name="liste_figurine" method="post">
<input type="checkbox" id="radio-1" class="z" name="chck1[]" onclick="updateCount()" />
<input type="checkbox" id="radio-2" class="z" name="chck2[]" onclick="updateCount()" />
</form>
<div id="y"></div>
Here is my JS :
function updateCount {
var x = $(".z:checked").length;
document.getElementById("y").innerHTML = x;
};
Here is an exemple : https://jsfiddle.net/r3todbs6/3/
Sorry, I'm not really used to JS... What is wrong with my code ?
Finally, it's working but I have one last issue : the onclick must contain 2 functions and I don't manage to make them working together.
Now this function works, alone : onclick="updateCount()"
This other function works also, alone : onclick="document.getElementById(\'radio-'.$ligne['id'].'-2\').checked = false"
But these two functions doesn't work, together :
onclick="updateCount(); fx2(document.getElementById(\'radio-'.$ligne['id'].'-1\').checked = false);"
What is wrong with the third proposition ? Is it a syntax error ?
.size()should be.length.lengthis not.length().forEach(value => { })to check value of checkbox and count it s amount under conditiondocument.querySelectorAll(".z:checked").length