Click to See Complete Forum and Search --> : Checkbox validation


veghead
07-07-2003, 06:05 AM
I faced one problem on create a validation for checkboxs in a form..

Said i have 10 boxes in my forms for selection, but my condition is maximun onli can select 5 out of 10...

can anyone pls show me how should i do it?:)

Gollum
07-07-2003, 06:17 AM
assuming you have given the checkboxes the same name, the following code may help...


<form name=theForm>
<input type=checkbox name=myCheck>Check 1
<input type=checkbox name=myCheck>Check 2
<!-- etc -->
</form>
<script>
function CheckBoxes()
{
var i, n = document.theForm.myCheck.length;
var count = 0;
for ( i = 0; i < n; i++ ) if ( document.theForm.myCheck[i].checked ) count++;
if ( count > 5 ) alert('Too many checkboxes');
}
</script>

veghead
07-07-2003, 07:13 AM
Many Thanks it works....:D :D