i have some checkbox:

<input type="checkbox" name="a" value="a" onclick="check(this)" />a
<input type="checkbox" name="b" value="b" onclick="check(this)" />b
<input type="checkbox" name="c" value="c" onclick="check(this)" />c
<input type="checkbox" name="d" value="a" onclick="check(this)" />a

if user select >= 2choices, the other checkbox become disable and < 2choices become enable.. so user max choose 2 choices.. if user not choose alert will show...

anybody can give a sample code like this.. i've try in googling but i can't find like this problem..


Ardy Satria - forzadraco

Hi forzadraco!

I have the following code for you.Please see if this code serve your purpose. If you are satisfied with the code , please mark it Solved.

<SCRIPT language=JavaScript type=text/javascript>
function check(){
	var i;
	var j=0;
	var chk;
		chk=document.getElementById("a" + i).checked;
				document.getElementById("a" + i).checked=false;
				alert("You cannot choose more than two options");

	<INPUT id="a1" name="a1" type=checkbox onClick="check()">A<BR>
	<INPUT id="a2" name="a2" type=checkbox onClick="check()">B<BR>
	<INPUT id="a3" name="a3" type=checkbox onClick="check()">C<BR>
	<INPUT id="a4" name="a4" type=checkbox onClick="check()">D

First you add the JavaScript code and then add the HTML form code.

With Regards

Rupam Datta