Hey Ya'll
I have a bit of a problem with a script im writing and was wondering if someone could help me out.
I have a number of checkboxes that are dynamically created using the following:
<input type="checkbox" name="we_cater_to[]" value="<?php echo $rowresult['value'];?>" <?php if($plan == 'Free') {?> onclick="chkcontrol(<?php echo $control; ?>)" <?php } else {} ?>>
I also have a javascript function that limits the amount of checkboxes clickable to 3 which is as follows:
<script type="text/javascript">
function chkcontrol(j) {
var total=0;
for(var i=0; i < document.createlisting.we_cater_to.length; i++){
if(document.createlisting.we_cater_to[i].checked){
total =total +1;}
if(total > 3){
alert("Please Select only three")
document.createlisting.we_cater_to[j].checked = false ;
return false;
}
}
} </script>
The problem im having is with the name of the checkboxes "we_cater_to[]" ... If i remove the [] at the end it all works perfect, except that the checkboxes dont save in the way i want them to ... so i need the [] to make the array ... and if i add [] to the javascript function then the function doesnt work at all.
How do i get the javascript to work using the [] ?
Any help would be great, i have been racking my brains and cant seem to get a result.
Cheers,