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

Printing... and locking a Field with Javascript?

tumbtack
Registered: Sep 4 2009
Posts: 6
Answered

I'm trying to make a form and I need two things that I cant get to work.

First, A unique number is created in a field on opening the document. This is an action on opening the document made like this:

// Get and Format Date
var currDate = new Date();
var strDate = util.printd("yyyymmddHHMMss",currDate);

// Display date on pages
this.getField("CurrentDocDate").value = strDate

20090913162508 is the outcome

The value it return is the current yearmonthdayhourminutesecond. When saving the document and opening it again e.g. for completing the form, the number is changed. I want it to lock after creating the number.

The second thing is printing.

The document has a few (15) userinputfields, and most of them are required or required if some other value is inserted.

I want to create an action that disallows printing and saving when not all required fields are filled in.

how do I create that?

the options I looked for on this forum did'nt do it for me.

Forgive my english, I'm dutch, and do not have much understanding of Javascript. Starting new. Originally creating the forms in Indesign, but now our customers want these kind of functions added.
I have 9. but it needs to be working with 8

My Product Information:
Acrobat Pro 9.1.3, Macintosh
try67
Expert
Registered: Oct 30 2008
Posts: 2398
1. You can add a condition to the script checking if there's already a value there. Something like this:
if (this.getField("CurrentDocDate").value==null || this.getField("CurrentDocDate").value=="") {
// the rest of the script

}
That way the field will only be filled once (make sure you set it to read-only, so the user can't change it manually)

2. The user will always be able to print the form through Acrobat, by going to File - Print, or pressing Ctrl+P. You can't prevent that. What you can do is add a WillPrint script that alerts the user if not all data is filled in. You can also create a "Print" button on your form. In that button you can prevent printing if not all data is filled in.

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

tumbtack
Registered: Sep 4 2009
Posts: 6
I tried several scripts for willprint. None of them did what I wanted. I have a print button on the form, and should add a script there?
try67
Expert
Registered: Oct 30 2008
Posts: 2398
In the WillPrint action you can add an app.alert() message saying something like "Not all the data is filled in", if that's the case.
In the print button on your form you can make the printing conditional. You add some if sentences that check if the data is filled in correctly, and if it's not you don't call the print method.

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

tumbtack
Registered: Sep 4 2009
Posts: 6
try67 wrote:
In the WillPrint action you can add an app.alert() message saying something like "Not all the data is filled in", if that's the case.
In the print button on your form you can make the printing conditional. You add some if sentences that check if the data is filled in correctly, and if it's not you don't call the print method.
I get the idea. Like I said, Javascript is new for me. Until now it was always possible to make forms with the tools Acrobat handed me. In this case, maybe I had to start in LCD, but we didnt. I will try the look further around for a script that works for me. My boss has plans for a course in Javascript, and then especially for forms, so maybe in the near future its possible for me to answer some questions.

for now, I have to do it with scripts that are handed to me. I printed the Acrobat API for Javascript, and trying to understand the way it works.

Thanks for sharing!
samuel3132
Registered: Sep 16 2009
Posts: 1
I am afriad to say that i did not get the question,But what i understand is that you are new to javascript .Inorder to get a field,ou have to use the method getElementbyId("id").But you have used the GetField method.So that is why you are not getting the desired output and the answers to the second question is to write a condition to enable or disable printing depending upon the user filled fields.
[url=http://www.litmatelas.com/matelas-gonflable.asp/]matelas gonflables[/url]

[url=http://www.litmatelas.com/matelas-gonflable.asp/]matelas gonflables[/url]

try67
Expert
Registered: Oct 30 2008
Posts: 2398
samuel3132 wrote:
Inorder to get a field,ou have to use the method getElementbyId("id").But you have used the GetField method.
You are providing wrong information. There's no such method as getElementbyId() in Acrobat JavaScript. It is NOT the same as the JavaScript that is used in a browser!

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