Solved

Forms Unlimited ?

Posted on 1998-06-29
2
147 Views
Last Modified: 2011-09-20
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 ...
0
Comment
Question by:BlackSun
2 Comments
 

Author Comment

by:BlackSun
ID: 1844435
Edited text of question
0
 
LVL 28

Accepted Solution

by:
sybe earned 60 total points
ID: 1844436
<script>
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;
      }
}
</script>



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



0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question