Click here to Skip to main content
15,892,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
<p id="result">Total correct = <p>  
<script>
showChecked();
function showChecked(){
  document.getElementById("result").textContent = "Total correct = " + document.querySelectorAll("input:checked").length;
}
document.querySelectorAll("input[name=correct]").forEach(i=>{
 i.onclick = function(){
  showChecked();
 }
});


What I have tried:

<p id="result">Total correct = <p>  
<script>
showChecked();
function showChecked(){
  document.getElementById("result").textContent = "Total correct = " + document.querySelectorAll("input:checked").length;
}
document.querySelectorAll("input[name=correct]").forEach(i=>{
 i.onclick = function(){
  showChecked();
 }
});
Posted
Updated 14-Jul-20 21:44pm

1 solution

You can use the document.querySelectorAll, as an example -

Java
var names = ["correct"]

for (let i = 0; i < names.length; i++)
{
  let temp = names[i];
  let things = document.querySelectorAll(`[name="${temp}"]`);
  console.log(temp, "count:", things.length);
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900