Script Categories













Forms >>> Limit Boxes.

Limits the number of checkboxes that the user is able to check on your site. Ideal for situations when more than one selection is allowed up to a certain number overall. If they select too many, they are notified of the maximum allowed and their last entry becomes unchecked.

Please choose up to 2 sections:

Section 1

Section 2

Section 3

Add the below code to the <body> section of your page:

<script language="javascript" type="text/javascript">
/* Visit http://www.yaldex.com/ for full source code
and get more free JavaScript, CSS and DHTML scripts! */
<!-- Begin
function countChoices(obj) {
max = 2; // max. number allowed at a time

box1 = obj.form.box1.checked;  // your checkboxes here
box2 = obj.form.box2.checked;
box3 = obj.form.box3.checked;  // add more if necessary

count = (box1 ? 1 : 0) + (box2 ? 1 : 0) + (box3 ? 1 : 0);
// If you have more checkboxes on your form
// add more  (box_ ? 1 : 0)  's separated by '+'

if (count > max) {
alert("Oops!  You can only choose up to " + max + " choices! \nUncheck an option if you want to pick another.");
obj.checked = false;
   }
}
//  End -->
</script>
<form>
Please choose up to 2 sections:
<p>
<input type=checkbox name=box1 onClick="countChoices(this)">Section 1
<p>
<input type=checkbox name=box2 onClick="countChoices(this)">Section 2
<p>
<input type=checkbox name=box3 onClick="countChoices(this)">Section 3
<p>
</form>

JavaScript Editor Get Advanced
JavaScript and Ajax Editor,
Validator and Debugger!

1st JavaScript Editor.



Code was highlighted by 1st JavaScript Editor (The Best JavaScript Editor!).




©