Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


Javascript to turn fields ON and OFF

Community Beginner ,
Sep 06, 2021 Sep 06, 2021

Copy link to clipboard

Copied

In Acrobat Pro DC I have a form with many fields. I would like to make a button that when clicked will turn OFF 20 of those fields. When I click the button again it will turn ON those 20 fields. Currently I am able to do that with 2 buttons using javascript. One button is the OFF button and the other button is the ON button. I no longer want to use 2 buttons to do this. Is it possible to use just 1 button to turn the 20 fields OFF and ON by clicking the one button once or twice.

TOPICS
How to

Views

36

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
community guidelines
Adobe Community Professional ,
Sep 06, 2021 Sep 06, 2021

Copy link to clipboard

Copied

By ON/OFF you mean to set field to readonly?

Since you didn't provide fields names, use this:

this.getField("Text1").readonly = this.getField("Text1").readonly == false ? true : false;

Change field name to your field name and repeat line for other fields.

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
community guidelines
Community Beginner ,
Sep 06, 2021 Sep 06, 2021

Copy link to clipboard

Copied

Nesa,

You are a God send. Thank you so much for your help. When the fields are
turned OFF they are no longer highlighted in blue and can only be read not
filled in with text. When the fields are turned ON they are now highlighted
in blue and you can enter text. This is the javascript I am using now for 2
buttons, one for OFF and one for ON. I want to incorporate it so I only
have to click one button to turn the fields OFF or ON by clicking the
button twice. Hope I am making myself clear.
-------------------------

*BUTTON 1 NO – Turns OFF Juvenile Text Fields*

this.getField("Juvenile Name").readonly =true; this.getField("Juvenile
Address").readonly =true; this.getField("Juvenile Residence
Phone").readonly =true; this.getField("Juvenile Business Phone").readonly
=true; this.getField("Juvenile Notified By").readonly =true;
this.getField("Juvenile Date").readonly =true; this.getField("Juvenile
Time").readonly =true; this.getField("Juvenile Disposition").readonly
=true; this.getField("Juvenile Released To").readonly =true;
this.getField("Juvenile Released Date").readonly =true;
this.getField("Juvenile Released Time").readonly =true;
this.getField("Juvenile By Name").readonly =true; this.getField("Juvenile
Reason").readonly =true; this.getField("Juvenile School Attended").readonly
=true; this.getField("Juvenile Grade").readonly =true;
this.getField("Juvenile Description of Property").readonly =true;
this.getField("Juvenile Value of Property").readonly =true;
this.getField("Juvenile Check Parent").readonly =true;
this.getField("Juvenile Check Legal Custodian").readonly =true;
this.getField("Juvenile Check Other").readonly =true;
this.getField("Juvenile Check Defendant").readonly =true;
this.getField("Juvenile Check Defendant Parents").readonly =true;
this.getField("Juvenile Check Yes 2").readonly =true;
this.getField("Juvenile Check Yes 1").readonly =true;
this.getField("Juvenile Check Yes Property Crime").readonly =true;
this.getField("Juvenile Check No Property Crime").readonly =true;

===========================

*BUTTON 2 YES – Turns ON Juvenile Text Fields*

this.getField("Juvenile Name").readonly =false; this.getField("Juvenile
Address").readonly =false; this.getField("Juvenile Residence
Phone").readonly =false; this.getField("Juvenile Business Phone").readonly
=false; this.getField("Juvenile Notified By").readonly =false;
this.getField("Juvenile Date").readonly =false; this.getField("Juvenile
Time").readonly =false; this.getField("Juvenile Disposition").readonly
=false; this.getField("Juvenile Released To").readonly =false;
this.getField("Juvenile Released Date").readonly =false;
this.getField("Juvenile Released Time").readonly =false;
this.getField("Juvenile By Name").readonly =false; this.getField("Juvenile
Reason").readonly =false; this.getField("Juvenile School
Attended").readonly =false; this.getField("Juvenile Grade").readonly
=false; this.getField("Juvenile Description of Property").readonly =false;
this.getField("Juvenile Value of Property").readonly =false;
this.getField("Juvenile Check Parent").readonly =false;
this.getField("Juvenile Check Legal Custodian").readonly =false;
this.getField("Juvenile Check Other").readonly =false;
this.getField("Juvenile Check Defendant").readonly =false;
this.getField("Juvenile Check Defendant Parents").readonly =false;
this.getField("Juvenile Check Yes 2").readonly =false;
this.getField("Juvenile Check Yes 1").readonly =false;
this.getField("Juvenile Check Yes Property Crime").readonly =false;
this.getField("Juvenile Check No Property Crime").readonly =false;

--
[Private information removed]

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
community guidelines
Adobe Community Professional ,
Sep 06, 2021 Sep 06, 2021

Copy link to clipboard

Copied

Nesa's script will do that. You can use an array with all the field names to do it more efficiently, like this:

 

var fields = ["Text1", "Text2", "Radio1", "Button4"]; // Change to actual field names
for (var i in fields) {
	var f = this.getField(fields[i]);
	f.readonly = !f.readonly;
}

 

PS. Please do not post your private details to this forum. You're likely to get contacted by scammers.

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
community guidelines
Community Beginner ,
Sep 06, 2021 Sep 06, 2021

Copy link to clipboard

Copied

Try67,

Thank you for that. Just so you know I have 2 left hands. The script I
showed you was given to me by someone answering my question about 2 years
ago. I understand the part of entering my field names in
{"Test1","Text2","Radio1","Button4"} but I am not sure about (var i in
fields) { var f = this.getField(fields[i]); f.readonly = !f.readonly; }

Is it possible for you to do a few lines for me?

Thank you,
Lance

--
[Private information removed, 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
community guidelines
Adobe Community Professional ,
Sep 06, 2021 Sep 06, 2021

Copy link to clipboard

Copied

LATEST

The only thing you need to change is the names of the fields between the quotes in the first line of code.

Do not change anything else. Also, I don't understand why you changed the first line from having square brackets (like in my example) to curly ones...

 

And stop replying via email! It includes your full contact details in the signature of each reply.

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
community guidelines