This forum is no longer open and is for reading/searching only.
Please use our new MachForm Community Forum instead.
MachForm Community Forums » MachForm 2
Validation Rule for checkboxes
Started 14 years ago by popuskin | 3 posts |
-
Hey People,
I have checkboxes with 8 items. I only want users to select not more than 3 items.
Where can I set this? I am a php developer.Thanks
Posted 14 years ago # -
Hi,
You can put the custom validation code in "includes/post-functions.php" file and use the method that posted in here :
http://www.appnitro.com/forums/topic/require-2-of-5-multiple-choice-answers#post-7367
MachForm Support
Posted 14 years ago # -
Hi redityo,
Thanks for your prompt response but I would appreciate a more direct approach to this issue. Below are my validation codes and the checkbox itself. Please explain how and what I should do.
<HTML>
<HEAD>
<TITLE> New Document </TITLE></HEAD>
<BODY>
<html>
<head>
<title></title>
<META NAME="DESCRIPTION" CONTENT="">
<META NAME="KEYWORDS" CONTENT=""><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>
</head><body topmargin=''0''; >
<form name=form1 method=post action=check.php>
<table border=''0'' width=''250'' cellspacing=''0'' cellpadding=''0'' align=center><tr bgcolor=''#ffffcc''><td > </td><td ><b>Choice</b></td></tr>
<tr bgcolor=''#f1f1f1'' ><td ><input type=checkbox name=ckb value=1 onclick=''chkcontrol(0)'';></td><td >PHP</td></tr>
<tr bgcolor=''#ffffff'' ><td ><input type=checkbox name=ckb value=2 onclick=''chkcontrol(1)'';></td><td >Perl</td></tr>
<tr bgcolor=''#f1f1f1'' ><td ><input type=checkbox name=ckb value=3 onclick=''chkcontrol(2)'';></td><td >MySQL</td></tr>
<tr bgcolor=''#ffffff'' ><td ><input type=checkbox name=ckb value=4 onclick=''chkcontrol(3)'';></td><td >ASP</td></tr>
<tr bgcolor=''#f1f1f1'' ><td ><input type=checkbox name=ckb value=5 onclick=''chkcontrol(4)'';></td><td >JavaScript</td></tr>
<tr bgcolor=''#ffffff'' ><td ><input type=checkbox name=ckb value=6 onclick=''chkcontrol(5)'';></td><td >CSS</td></tr>
<tr bgcolor=''#f1f1f1'' ><td ><input type=checkbox name=ckb value=7 onclick=''chkcontrol(6)'';></td><td >HTML</td></tr>
<tr bgcolor=''#ffffff'' ><td ><input type=checkbox name=ckb value=8 onclick=''chkcontrol(7)'';></td><td >Photo Shop</td></tr>
</table></form>
</body>
</html>
</BODY>
</HTML>Posted 14 years ago #
Reply
You must log in to post.