I have a need to limit the number of checkboxes that are chosen in a form.

EXAMPLE:

(A) Choose 1 category

(B) Choose up to 3 categories

If the user chooses (A), so they can only pick one category, from a drop down box.

What I need to do, is limit the number of selections if they choose (B) as I'm displaying a checkbox list of categories. If I have 72 categories, I want them to only be able to choose a max of 3 (three), not all 72.

Is this possible? What is the easiest way to implement this?