Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Javascript help

Community Beginner ,
Jan 22, 2020 Jan 22, 2020

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]

TOPICS
Create PDFs
1.6K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 22, 2020 Jan 22, 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 PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 23, 2020 Jan 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 23, 2020 Jan 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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 23, 2020 Jan 23, 2020

Assuming those are the export values, like this:

this.getField("Field B").required = this.getField("Checkbox A").valueAsString=="Pediatric Care";

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 23, 2020 Jan 23, 2020

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")');

 

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 23, 2020 Jan 23, 2020

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!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 23, 2020 Jan 23, 2020

post a screenshot of your submit options.

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 23, 2020 Jan 23, 2020

a1.pngexpand imagea2.pngexpand image

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 23, 2020 Jan 23, 2020

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 23, 2020 Jan 23, 2020

I'd be happy to. Can I have a private email address please?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 23, 2020 Jan 23, 2020

[try6767 at gmail.com]

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 23, 2020 Jan 23, 2020
LATEST

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. 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines