rjra2
07-03-2003, 01:30 PM
I have 4 checkboxes in a formand i want to allow users to check any 2 of them not all 4. I just learning JavaScript and could use some real help with this.
Thanks
Thanks
|
Click to See Complete Forum and Search --> : Limit checkboxes being checked rjra2 07-03-2003, 01:30 PM I have 4 checkboxes in a formand i want to allow users to check any 2 of them not all 4. I just learning JavaScript and could use some real help with this. Thanks Jona 07-03-2003, 02:24 PM <script type='text/javascript'> <!-- // Untested code function calc(){ var chkd; var count = 0; for(i=1; i<document.myForm.elements.length; i++){ if(document.myForm.elements[i].type=="checkbox" && document.myForm.elements[i].checked==true){ count+=1; } if(count>2){alert("Check only one, please."); return false;} } //--> </script></head> <body> <form action="" name="myForm" onsubmit="return calc();"><div> <input type="checkbox" name="c1"><br> <input type="checkbox" name="c2"><br> <input type="checkbox" name="c3"><br> <input type="checkbox" name="c4"><br> <input type="submit" value="Submit"> </div></form> </body></html> [J]ona webdeveloper.com
Copyright Internet.com Inc., All Rights Reserved. |