These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Need script to make pdf form fields uneditable when a Button is pressed

Slivar
Registered: May 29 2010
Posts: 16
Answered

Hi Guys,
 
I need some help with this script desperately. I am using Acrobat X Professional on Mac.
 
Here's the situation, I have tried inserting this script on a button, it comes up with the warning window, but it doesn't lock the form from editing after I click YES. On this button I have also added a Save As command.
 
My PDF is 1 page and here are the fields that I have in the pdf that are named as follows:
 
CustomerName
Address_Line1
Address_Line2
Kitchen_Style
Deposit_1
Deposit1_Amount
Deposit_2
Deposit2_Amount
Deposit_3
Deposit3_Amount
Deposit_4
Deposit4_Amount
Save_Button
 
This is the script I have used.
 
// The following code confirms whether to Lock the form
 
var cMsg = "Is this form ready to be submitted? \n\n"
cMsg += "Select YES to LOCK the form.\n\n"
cMsg += "Do you want to Continue?\n\n"
var nRtn = app.alert(cMsg,1,2, "Lock Form?");
if(nRtn == 4)
{ // A Yes Answer
 
//Protects each field
 
CustomerName.access = "protected";
Address_Line1.access = "protected";
Address_Line2.access = "protected";
Kitchen_Style.access = "protected";
Deposit_1.access = "protected";
Deposit1_Amount.access = "protected";
Deposit_2.access = "protected";
Deposit2_Amount.access = "protected";
Deposit_3.access = "protected";
Deposit3_Amount.access = "protected";
Deposit_4.access = "protected";
Deposit4_Amount.access = "protected";
Save_Button.access = "protected";
}
endif;
  
Can somebody help me ASAP and tell what I am doing wrong??
 
All I want to do is make the fields uneditable/locked after I hit the button.
 
Thanks
Sash

My Product Information:
Acrobat Pro 10.0.1, Macintosh
try67
Expert
Registered: Oct 30 2008
Posts: 2398
Is this a LiveCycle form?

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

Slivar
Registered: May 29 2010
Posts: 16
No it's an Acrobat form. Also, with the pop up window that comes up I need to put an extra script in there so when I press No it will cancel all and return to the PDF file.

I hope this makes sense.
try67
Expert
Registered: Oct 30 2008
Posts: 2398
Then I don't know how you came up with this code.
- You're not accessing fields correctly
- You're not using correct JS syntax for the if-statement
- You're trying to use a non-existing property of the Field objects ("access")

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

Slivar
Registered: May 29 2010
Posts: 16
I got this script from another thread, I think it was for LiveCycle.

Anyhow, how would I accomplish this using Javascript?

Your help would be greatly appreciated.


try67
Expert
Registered: Oct 30 2008
Posts: 2398
Accepted Answer
Drop the endif.
Replace this line:
CustomerName.access = "protected";
with this:
this.getField("CustomerName").readonly = true;
(and the same for all the other lines as well)

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

try67
Expert
Registered: Oct 30 2008
Posts: 2398
PS - if you press No in the dialog the script will end and you'll return to the document.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

Slivar
Registered: May 29 2010
Posts: 16
Thanks for that, that done the trick.