Highlighted

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

Community Beginner ,
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?

Adobe Community Professional
Correct answer by ls_rbls | Adobe Community Professional

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.

 

 

TOPICS
How to, PDF forms

Views

31

Likes

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

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

Community Beginner ,
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?

Adobe Community Professional
Correct answer by ls_rbls | Adobe Community Professional

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.

 

 

TOPICS
How to, PDF forms

Views

32

Likes

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
Aug 24, 2020 0
Adobe Community Professional ,
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.

 

 

Likes

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
Reply
Loading...
Aug 24, 2020 1
Community Beginner ,
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"

Likes

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
Reply
Loading...
Aug 24, 2020 0
Community Beginner ,
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.

Likes

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
Reply
Loading...
Aug 24, 2020 1
ls_rbls LATEST
Adobe Community Professional ,
Aug 24, 2020

Copy link to clipboard

Copied

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

 

Would you mind marking the answer as correct solution.

Likes

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
Reply
Loading...
Aug 24, 2020 0