JS implements a method to count the number of checkboxes checked and prompt for confirm and cancel

  • 2020-06-22 23:54:04
  • OfStack

This article illustrates how JS implements the method of counting the number of check boxes checked and prompts for confirm and cancel. Share to everybody for everybody reference. Specific implementation methods are as follows:

Section javascript is as follows:


<script type="text/javascript"> 
function yesno() { 
  var inputs = document.getElementsByName("ck[]"); 
  var checked_counts = 0; 
  for(var i=0;i<inputs.length;i++){ 
    if(inputs[i].checked){checked_counts++; 
    } 
  } 
  if(confirm(" You have chosen  " + checked_counts + "  A website ,\n Are you sure you have chosen to remove the filtered url ?")){ 
   //return true; 
   ShowDiv('MyDiv','fade'); 
  }else{ 
   return false; 
  } 
}  
</script>

The html section is as follows:


<form id="form1" name="form1" method="post" action=""> 
<input type="checkbox" name="ck[]" id="ck[]" value="{$vo.id}" onclick="javascript:chkRow(this);"> 
<input type="checkbox" name="ck[]" id="ck[]" value="{$vo.id}" onclick="javascript:chkRow(this);"> 
<input type="checkbox" name="ck[]" id="ck[]" value="{$vo.id}" onclick="javascript:chkRow(this);"> 
<input type="checkbox" name="ck[]" id="ck[]" value="{$vo.id}" onclick="javascript:chkRow(this);"> 
<input type="checkbox" name="ck[]" id="ck[]" value="{$vo.id}" onclick="javascript:chkRow(this);"> 
<input type="checkbox" name="ck[]" id="ck[]" value="{$vo.id}" onclick="javascript:chkRow(this);"> 
<input type="checkbox" name="ck[]" id="ck[]" value="{$vo.id}" onclick="javascript:chkRow(this);"> 
<input type="checkbox" name="ck[]" id="ck[]" value="{$vo.id}" onclick="javascript:chkRow(this);"> 
<input type="checkbox" name="ck[]" id="ck[]" value="{$vo.id}" onclick="javascript:chkRow(this);"> 
<input type="checkbox" name="ck[]" id="ck[]" value="{$vo.id}" onclick="javascript:chkRow(this);"> 
<input type="submit" name="submit" id="submit" class="subbut" onclick="return yesno();" value=" Select Delete information "> 
</form> 

Hopefully, this article has helped you with your javascript programming.


Related articles: