Categories:

Home / Free JavaScripts / Forms / Here

Cut & Paste Limit number of checked checkboxes script

Credit: JavaScript Kit

Description: This short but practical script lets you limit the number of checkboxes within a group that can be checked. For example, you may have a list of 5 checkboxes, but wish to allow the user only the ability to check a maximum of 2 at any time. Use this script to accomplish that.

Example: Please select your top 2 favourite countries below:

USA
Canada
Japan
China
France

Directions

Step 1: Insert the following script into the <HEAD> section of your page:

Step 2: Add the below sample form into the <BODY> section:


As illustrated at the end of the code of Step 2, just call the function checkboxlimit() following the form with the checkboxes in question with the following syntax:

//Syntax: checkboxlimit(checkbox_reference, limit)

For example:

checkboxlimit(document.forms.world.countries, 2)
JavaScript Tools:
Site Info

CopyRight 1998-2012 JavaScript Kit. NO PART may be reproduced without author's permission.