Solved

Forms Unlimited ?

Posted on 1998-06-29
2
148 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

752 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