Javascript help
Copy link to clipboard
Copied
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]
Copy link to clipboard
Copied
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
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Assuming those are the export values, like this:
this.getField("Field B").required = this.getField("Checkbox A").valueAsString=="Pediatric Care";
Copy link to clipboard
Copied
Or you could include the required property in the reset script, to reduce the calculation load on the form.
Or you could add the script to the validate event on the checkbox by running this code in the Console
this.getField("Checkbox A").setAction("Validate",'this.getField("Field B").required = (event.value != "Off")');
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
Thank you both so very much.
Just one more question...I followed instructions on a link provided within this community in an attempt to create a submit button that will link to an Outlook inbox. I received that error message "You need to be running inside a web browser in order to submit this form." I assume these instructions were incorrect. I went through the Actions tab>Submit a form. Your continued help is greatly appreciated!
Copy link to clipboard
Copied
post a screenshot of your submit options.
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Your URL doesn't seem correct, but it should only work when you click the button.
If it's still working when you just move the cursor over it make sure you didn't create multiple overlapping fields at the same location.
If you still can't figure it out share the file with us, please.
Copy link to clipboard
Copied
I'd be happy to. Can I have a private email address please?
Copy link to clipboard
Copied
[try6767 at gmail.com]
Copy link to clipboard
Copied
That's not a proper URI. And it's not a good practice to use application specific URI protocals, unless you know the exact envrionment inwhich it will be used? What is it you are trying to do? If you're emailing the PDF then use the "mailto:" prefix.
Use the Acrobat JavaScript Reference early and often

