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

Need JS to validate Checkboxes

moto427
Registered: Jun 3 2010
Posts: 16

I need the JS to require a user to select at least 1 checkbox, but the user can also select multiple checkboxes. I have a submit button on the form. When the user clicks submit, if they haven't selected one of the check boxes then a message should appear and not let the user submit the email.

I am new to JS, so I would need the code and how to make it work. I am using Adobe Acrobat Standard 9.

Thanks!

My Product Information:
Acrobat Standard 9.3.1, Windows
try67
Expert
Registered: Oct 30 2008
Posts: 2398
You will need something like this:

if (this.getField("checkbox1").value=="Yes" || this.getField("checkbox2").value=="Yes" || this.getField("checkbox3").value=="Yes") {this.submitForm();} else {app.alert("You must check at least one of the check boxes before submitting.");}

You will need to adjust the names and values of the check boxes as well as the proper parameters for submitting the form.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

moto427
Registered: Jun 3 2010
Posts: 16
The pop up appears if no check boxes are marked, but it will still create an email to send. Is there a way to prevent it from creating the email when there are no check boxes selected?
try67
Expert
Registered: Oct 30 2008
Posts: 2398
You need to use only this code. Don't add any other action to the Submit button, because the validation will not affect those actions. Submitting the form should be done from the code I provided you.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

moto427
Registered: Jun 3 2010
Posts: 16
The submit button does not do anything when I click on it now.

If the fields are checked properly, then I would like it to submit the form as a PDF to an email address such as: name [at] mycompany [dot] com.How is done? I appreciate your help. Thanks.
try67
Expert
Registered: Oct 30 2008
Posts: 2398
Replace:
this.submitForm();
With this:
this.mailDoc({bUI:true, cTo: "name [at] mycompany [dot] com"});

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

moto427
Registered: Jun 3 2010
Posts: 16
Works awesome! Thanks!
moto427
Registered: Jun 3 2010
Posts: 16
I found another issue. In addition to those checkboxes, I also have text fields and radio buttons that are required. With this code, they are not being validated any more. They used to be validated when I would click the submit button. A message would pop up as well.

Is there a fix for this?
try67
Expert
Registered: Oct 30 2008
Posts: 2398
You will need to expand the script to check those fields as well.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

Tekexpert
Registered: Mar 31 2010
Posts: 18
Hi Mauricio,

can you please share this PDF with validated checkbox with me. I am new to javascript, and having same problem...
Can you please send that file at---meetshweta23atgmail.com

Many Thanks in advance...