How to limit use to choose only 2 value in a checkbox?

I have a field of type checkbox (on web).

The field contains 15 values that the user may choose from.

I want to limit the user to choose only 2 of the values. How can I do it?

Subject: How to limit use to choose only 2 value in a checkbox?

Hi Lena,a very easy way to limit the elements in a checkbox is to use the Input Translation:

@IF(@ELEMENTS(selection)>2;@Subset(selection;2);selection)

(selection is the field name of your checkbox)

More than two selections can be made at first, but after a save or refresh the values in that field will be reduced to two.

Subject: How to limit use to choose only 2 value in a checkbox?

This JavaScript snippet might work, in your submission validation:

f = document.forms[0];

count = 0;

max = 2;

for (m = 0; m < f.list.options.length; m++){

if (f.list[m].selected == true){

	count = count + 1;

}

if (count > max) {

	alert( "Hey, it's more than " + max + "!");

	return false;

}

}

Subject: How to limit use to choose only 2 value in a checkbox?

Sorry, just re-read your post and noted this was for the web only - ignore the earlier version of this response!

There are plenty of Javascript validation routines out there. Simply pick one and validate the # of SELECTs made for the field.

Subject: How to limit use to choose only 2 value in a checkbox?

Check out Forms in HTML documents for information on the SELECT element. The MULTIPLE option allows you to pick more than one, but not exactly how many more. I suggest that you use a JavaScript validation function in the onSubmit event of the form, and count how many have been selected, failing if the number is over your allowed maximum. There’s a pretty good discussion of the topic on http://www.mattkruse.com/javascript/selectbox/.