Solved

Forms Unlimited ?

Posted on 1998-06-29
2
143 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…

707 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now