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

Acrobat Adobe Pro DC: Javacode for disabling a fillable form question based on prior selections.

Community Beginner ,
Aug 24, 2020 Aug 24, 2020

Copy link to clipboard

Copied

I am not familiar with how to write code and have had no luck searching the internet to do what I am trying to do. I have found a few codes, but they aren't working in this version. 

 

I am trying to disable a selection in "prepare forms" in adobe acrobat pro DC based on a checkmark being checked in the question before it. 


I believe it has to do with javascript and mouse up inside properties, but I am not sure how to write the code to perform the action. This is what I found and tried to use. Basically I am trying to make my "primary medical group number" text box gray out/disable if the checkmark for the  "registration opt out" box is checked. 

 

// Function to enable form fields function
EnableFormField (Primary Medical Group Number) {
// First acquire the field to be enabled
var oFld = this.getField(Registration Opt Out)
{
// Make field interactive
oFld.readonly = false;
// Restore Normal Colors
oFld.fillColor = oNmlFld.fillColor;
oFld.borderColor = oNmlFld.borderColor;
oFld.textColor = oNmlFld.textColor;
}
}
// Function to disable form fields function
DisableFormField(Registration Opt Out) {
// First acquire the field to be disabled
var oFld = this.getField(Primary Medical Group Number)
if(oFld) {
// Make field Read-Only
oFld.readonly = true;
// Set Grayed out colors
oFld.fillColor = ["G", 0.75]; oFld.borderColor = ["G", 2/3]; oFld.textColor = ["G", 0.5];

 

Can someone help me figure out what I am doing wrong?

TOPICS
How to , PDF forms

Views

440

Translate

Translate

Report

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

correct answers 1 Correct answer

Community Expert , Aug 24, 2020 Aug 24, 2020

You don't need a document level script just to do that.

 

The script  that you copy and pasted here is part of a tutorial developed by Adobe ACP, Thom Parker. It is found here: https://acrobatusers.com/tutorials/print/js_disabling_fields/

 

To disable a a field (regardless if it has a selection or not in it) you can use a very simple script as a mouse-up action in that checkbox

 

When the checkbox is ticked (checked state), it will convert that other field as read only and additionally change the colo

...

Votes

Translate

Translate
Community Expert ,
Aug 24, 2020 Aug 24, 2020

Copy link to clipboard

Copied

You don't need a document level script just to do that.

 

The script  that you copy and pasted here is part of a tutorial developed by Adobe ACP, Thom Parker. It is found here: https://acrobatusers.com/tutorials/print/js_disabling_fields/

 

To disable a a field (regardless if it has a selection or not in it) you can use a very simple script as a mouse-up action in that checkbox

 

When the checkbox is ticked (checked state), it will convert that other field as read only and additionally change the color to gray to give the  visual appearance that it is disabled. And then add another line to the same script to enable that field the checkbox is unchecked.

 

It would look something like this:

 

if (event.target.value !="Off") {
this.getField("Primary Medical Group Number").fillColor = color.ltGray;
this.getField("Primary Medical Group Number").textColor = color.gray;
this.getField("Primary Medical Group Number").readonly = true;
this.getField("Primary Medical Group Number").strokeColor = color.gray;
this.getField("Primary Medical Group Number").lineWidth = 1;

} else { 

this.getField("Primary Medical Group Number").fillColor = color.transparent;
this.getField("Primary Medical Group Number").textColor = color.black;
this.getField("Primary Medical Group Number").readonly = false;
this.getField("Primary Medical Group Number").strokeColor = color.black;
this.getField("Primary Medical Group Number").lineWidth = 1;


}



 

 

You can insert this script in the checkbox field as a mouse-up action javascript(shown below):

 

jscriptmouse-up.png

 

When you click on  "Edit" you may paste this script in the javascript editing window that wil open up.

 

In the script above, I am using as a reference the  Adobe Acrobat SDK JavaScript API Reference,  "Field methods", Page. 420.

 

 

Votes

Translate

Translate

Report

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 ,
Aug 24, 2020 Aug 24, 2020

Copy link to clipboard

Copied

Thanks, but now I am getting an error. It says: "SyntaxError: missing } in compound statement 14: at line 15"

Votes

Translate

Translate

Report

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 ,
Aug 24, 2020 Aug 24, 2020

Copy link to clipboard

Copied

actually I figured out where it was missing and that worked! THANK YOU SO MUCH! I was working on this all morning. So glad I thought to post. You helped so much. Thanks again.

Votes

Translate

Translate

Report

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 ,
Aug 24, 2020 Aug 24, 2020

Copy link to clipboard

Copied

LATEST

You're very welcome and I'm happy to assist.

 

Would you mind marking the answer as correct solution.

Votes

Translate

Translate

Report

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