• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 155
  • Last Modified:

Forms Unlimited ?

Is it possible to set a maximum number of checkboxes checked in a form ?

I have 10 answers but i don't want the user to check more than 4 ! there should be some kind of alert " you cannot check more than 4 boxes" or something like that !
is that possible ? if so .. HOW ??
thanks ...
1 Solution
BlackSunAuthor Commented:
Edited text of question
var BoxesChecked = 0;
function CheckTotalNumber(name) {
      if (BoxesChecked < 4 && name.checked) {
            BoxesChecked = BoxesChecked + 1;
      } else if (name.checked) {
            alert("You can only check 4 items");
            name.checked = false;
      } else if (!name.checked) {
            BoxesChecked = BoxesChecked - 1;

<INPUT type=checkbox name="checkbox1" onClick="CheckTotalNumber(this)"> checkbox1
<INPUT type=checkbox name="checkbox2" onClick="CheckTotalNumber(this)"> checkbox2
<INPUT type=checkbox name="checkbox3" onClick="CheckTotalNumber(this)"> checkbox3
<INPUT type=checkbox name="checkbox4" onClick="CheckTotalNumber(this)"> checkbox4
<INPUT type=checkbox name="checkbox5" onClick="CheckTotalNumber(this)"> checkbox5
<INPUT type=checkbox name="checkbox6" onClick="CheckTotalNumber(this)"> checkbox6
<INPUT type=checkbox name="checkbox7" onClick="CheckTotalNumber(this)"> checkbox7
<INPUT type=checkbox name="checkbox8" onClick="CheckTotalNumber(this)"> checkbox8
<INPUT type=checkbox name="checkbox9" onClick="CheckTotalNumber(this)"> checkbox9
<INPUT type=checkbox name="checkbox10" onClick="CheckTotalNumber(this)"> checkbox10

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now