These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Require at Least 1 Checkbox

moto427
Registered: Jun 3 2010
Posts: 16

I’m creating a form in Adobe Acrobat Standard 9. I have 4 check boxes on it. I want to require the user to select at least one, but the user can select more than one also.

The form has a Submit button that emails the form as a pdf.

What I want to do is when the user clicks the submit button, validate that at least one of the check boxes is checked. If not, do not allow the email and display an error message. I am new to Java Script and need exact code and instructions. Thanks!

My Product Information:
Acrobat Standard 9.1.3, Windows
smit462
Registered: May 20 2006
Posts: 20
I recently had a similar situation arise. This is not the most elegant solution, but here goes:

1. Create a 'required' text field behind your check boxes with white text (hopefully your background is white).

2. Add a calculation to the new text field to only include a value in it if one of the check boxes is marked:

var cb1 = this.getField("Check Box1").value;
var cb2 = this.getField("Check Box2").value;
var cb3 = this.getField("Check Box3").value;
var cb4 = this.getField("Check Box4").value;
if (cb1 == "Yes" || cb2 == "Yes" || cb3 == "Yes" || cb4 == "Yes"){this.getField("text field").value = 1;}
else {this.getField("text field").value = "";}

If one of the boxes is checked, the new required text box should be filled and satisfy the 'required' field.

3. Add the following Mouse Up/Run a Javascript action of the submit button (not using the Acrobat Submit menu):

var tf1 = this.getField("text field").value;
if (tf1 == 1){this.getField("text field").display = display.hidden;}
else {this.getField("text field").display = display.visible; app.alert("You forgot something.");}
this.submitForm("mailto:user [at] domain [dot] com");

STEVE MITTEL
Senior Forms Designer
Texas Comptroller of Public Accounts

gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
You could also check the check boxes for not being equal to ''Off', since 'Off' if the value of a check box when one in the group is not checked. And logically 'OR' the result will create a logical 'true' of 'false' of all of the test. The following code could be used for a submit button.

// create a logical variable for test// use OR to update value of test for each fieldvar bValid = (this.getField("Check Box1").value != 'Off'); // test if check box 1 checkedbValid = bValid | (this.getField("Check Box2").value != 'Off'); // test if check box 2 checkedbValid = bValid | (this.getField("Check Box3").value != 'Off'); // test if check box 3 checkedbValid = bValid | (this.getField("Check Box4").value != 'Off'); // test if check box 4 checked// test logical value of testif(bValid) {// true value - one or more boxes checkedapp.alert('submit action', 3, 0,'Submit');} else {// false or not true result - no check box selectedapp.alert("You need to select at least one check box.", 1, 0, 'Required Field');}

The above code will work with an exclusionary group of check boxes or independent check boxes, since a test for the group or button is made to see that the check box or group has a selection made and is not dependent upon the value of the selection. The code will also work for Radio Buttons.

George Kaiser