Control for checkboxes form not working

Hi there.

This control function Button1_onclick() for checkboxes in the my form not working, why?
Can u help me? :frowning:


<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
 
    <script language="javascript" type="text/javascript">
// <!CDATA[
 
function Button1_onclick() 
{
    if (!controllo_check())
    {
         alert("Stop");
        return;
    }
    document.forms[0].submit();
 
}
 
 
function controllo_check()
{
    var cks = document.forms[0].chkParent;
    var checked = false;
    for(var i = 0; i < cks.length; i++)
    {
        if(cks[i].checked)
        {
            checked = true;
            break;
        }
    }
    return checked; 
 
}
 
 
// ]]>
    </script>
 
</HEAD>
<title>Multiple checkbox select sample</title>
<BODY>
 

<form name=frmTest action="default-2.asp" method=POST onsubmit="return(Button1_onclick(this));" >
 
<input type=CHECKBOX name=chkParent1 value="3742">karla_c26<br>
 
<input type=CHECKBOX name=chkParent2 value="4430">AleAlvarez<br>
 
<input type=CHECKBOX name=chkParent3 value="3303">Alejandra<br>
 
<input type=CHECKBOX name=chkParent4 value="3720">Angio<br>
 
<input type=CHECKBOX name=chkParent5 value="3">gino<br>
 
<input type=CHECKBOX name=chkParent6 value="4606">Andrea<br>
 
<input type=CHECKBOX name=chkParent7 value="3962">alx<br>
 
<input type=CHECKBOX name=chkParent8 value="4095">ANGELADAUTO<br>
 
<input type=CHECKBOX name=chkParent9 value="7">cas<br>
 
<input type=CHECKBOX name=chkParent10 value="8">assim<br>
 
<input type=HIDDEN name=txtCount value="10">
<p><input type=SUBMIT value="Select"></p>
</form>
</BODY>
</HTML>

Just a guess, but I think you need to rename all the checkbox elements with the same name, “chkParent”. If you need to refer to a specific element within the array, you could call it by chkParent, or you could also add an id attribute for each one, using unique id values in the way you are setting your name values now.

Good luck!

Thank You for ur help !!!

This is the solution:


    <script language="javascript" type="text/javascript">
// <!CDATA[

function atLeastOneChecked(form) {

   var inputs = form.getElementsByTagName('input');
   var i = inputs.length;
   while (i--) {

   if (inputs[i].checked && !inputs[i].disabled) return confirm("Are you sure?");     

   }
   
   alert("ko!")
   return false;

}

// ]]>
    </script>

...
<form name=frmTest action="default-2.asp" method=POST onsubmit="return atLeastOneChecked(this)">
...
</form>