I’m working on a form where a person can select only a certain number of checkbox options. For instance, if there are 10 checkbox options, but they are only allowed to select three, is there a way in the form that you could create an error message when more than the alloted number have been choosen?
I haven’t seen anything like this in the forums, but I do see that it is possible to do it with JavaScript. I found this script through a quick Google search:
<script type="text/javascript">
function chkcontrol(j) {
var total=0;
for(var i=0; i < document.form1.ckb.length; i++){
if(document.form1.ckb[i].checked){
total =total +1;}
if(total > 3){
alert("Please Select only three")
document.form1.ckb[j].checked = false ;
return false;
}
}
} </script>
Is there a better way to do this in eForm, or would you recommend using the Java?
Thanks for your help in advance.
UPDATE: With more research, I found a simple JQuery plugin (Trilemma:
http://plugins.jquery.com/project/trilemma) that seems to work better, and is more simple to install. You merely assign a class to the fieldset.
In the previous Java posted above, it required onClick tags be entered on each input.
With the JQuery plugin, the form can be updated as needed, without much hassle.
I’m still interested to know if eForm provides any support for this internally though. Please let me know if anyone has any ideas around this.
Thanks.