Skip to main content
Participant
January 22, 2020
Question

Javascript help

  • January 22, 2020
  • 1 reply
  • 1848 views

Good morning,

I have been assigned a work project that I have no idea how to do 😞  I have created a fillable form using Adobe Pro and was only able to accomplish this through the use of YouTube videos. I am new to Adobe so any help I can get is greatly appreciated.

In my form, I need to format "Field B", to become a required field if "Checkbox A" is checked. . Is there a way to do this?

Thanks!

 
 

[Moving from generic Start/Help forum to the specific Program forum... Mod]
[To find a forum for your program please start at https://community.adobe.com/]

[Also, Adobe is the company name... the program is Acrobat]

This topic has been closed for replies.

1 reply

Thom Parker
Community Expert
Community Expert
January 23, 2020

That's not a formating issue, but here's the solution to your specifi issue.

 

Add this script to the MouesUp "Run a javaScript" action on the checkbox

 

this.getField("Field B").required = (event.value != "Off");

 

You can learn everything you need to know about PDF scripting here:

https://www.pdfscripting.com/public/main.cfm

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
try67
Community Expert
Community Expert
January 23, 2020

The solution provided by Thom will work, until you reset the form and then the text box will remain required (if it already was). I would do it a bit differently.

Assuming your text field doesn't have a calculated value, use this script as its custom calculation code:

 

event.target.required = this.getField("Checkbox A").valueAsString!="Off";

 

If it does have a calculated value you can use a different (hidden) text field to achieve it, using this code:

 

this.getField("Field B").required = this.getField("Checkbox A").valueAsString!="Off";

 

Using a calculation script instead of a MouseUp one will make sure the field is set as non-required when the form is cleared.

ib0920Author
Participant
January 23, 2020

This worked! Thank you so much!

Can you please tell me how I would require 1 checkbox to be checked from a list of checkboxes? For example, "What service are you requesting?"

  • Pediatric Care
  • Primary Care
  • Geriatric Care