Simple JavaScript check not working?
<p>I have this validate form function:</p>

<pre><code>function ValidateForm() {
    var chks = document.register.elements['sendto[]'];
    var hasChecked = false;
    for (var i=0;i&lt;chks.length;i++){
        if (chks[i].checked){
            hasChecked = true;
            break;
        }
    }
    if (!hasChecked){
        alert("Please select at least one friend.");
        chks[0].focus();
        return false;
    }
}
</code></pre>

<p>html for this is:</p>

<pre><code>&lt;input type="checkbox" name="sendto[]" value="2" &gt;
</code></pre>

<p>I know this is not full code. Full code is huge. But basically if i have only one checkbox in the code the above code gives a message undefined on ValidateForm(). Which is called when form is submitted and and above checkbox is checked. </p>

<p>But if i have two checkboxes in the code like this:</p>

<pre><code>&lt;input type="checkbox" name="sendto[]" value="2" &gt;
&lt;input type="checkbox" name="sendto[]" value="4" &gt;
</code></pre>

<p>On submit when ValidateForm() function is called this works correctly. Am i doing something wrong that it is not working for 1 checkbox even if it is checked?</p>
