New to JavaScript but fairly savvy learner

New Here ,
Sep 01, 2017

Copy link to clipboard

Copied

I want to create Adobe forms for internal employee use.  These forms will not be published on the web.  I created my first form and since it had fairly simple calculations I was able to muddle through it.  For my next project, there are some relatively simple formulas if I were using excel.  However, I need help with actually getting the process started.  Specific questions are:

1. Must I add custom calculation script to each individual box or can I use the JavaScript tool to write code for the entire form?

2. Where do I start since I am not publishing to html?  My research indicates that JavaScript should be placed into html code...do I really need to do this?

3. Before I get overly ambitious (it may be too late), I want to make sure it is possible to do what I want to do.  So based on the below, I want the PaymentD_"x" boxes to use the Repayment_Start_Date +14 days...thus a payment every two weeks. 

I think with these points answered, I will be able to move on.  Additionally, I already have JavaScript for beginners guides and books and have read this community thoroughly...so I know I have a lot of learning to do.  I really just need a point in the right direction to apply all of this.

TOPICS
Acrobat SDK and JavaScript

Views

127

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

New to JavaScript but fairly savvy learner

New Here ,
Sep 01, 2017

Copy link to clipboard

Copied

I want to create Adobe forms for internal employee use.  These forms will not be published on the web.  I created my first form and since it had fairly simple calculations I was able to muddle through it.  For my next project, there are some relatively simple formulas if I were using excel.  However, I need help with actually getting the process started.  Specific questions are:

1. Must I add custom calculation script to each individual box or can I use the JavaScript tool to write code for the entire form?

2. Where do I start since I am not publishing to html?  My research indicates that JavaScript should be placed into html code...do I really need to do this?

3. Before I get overly ambitious (it may be too late), I want to make sure it is possible to do what I want to do.  So based on the below, I want the PaymentD_"x" boxes to use the Repayment_Start_Date +14 days...thus a payment every two weeks. 

I think with these points answered, I will be able to move on.  Additionally, I already have JavaScript for beginners guides and books and have read this community thoroughly...so I know I have a lot of learning to do.  I really just need a point in the right direction to apply all of this.

TOPICS
Acrobat SDK and JavaScript

Views

128

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
Sep 01, 2017 0
Adobe Community Professional ,
Sep 01, 2017

Copy link to clipboard

Copied

#1 You can have one calculation script for your whole form. When I use that approach, I usually add a hidden and read-only field to the form that I then use to hold the "whole form calculation script". When you do that, you can no longer just use the "event.value" method of assigning values to a filed, you need to get the field, and then assign the value using it's value property:

this.getField("SomeField").value = this.getField("SomeOtherField").value * 2;

#2 Take a look here: Learning to Program JavaScript for Adobe Acrobat - KHKonsulting LLC - I wrote this up some time ago to help people to get into JavaScript for Acrobat. Other good resources are this book: Beginning JavaScript for Adobe Acrobat  and of course the http://pdfscripting.com web site.

You need to keep in mind that HTML and Acrobat JavaScript share a common core language, but when it comes to actually doing work in their respective environments, they are completely different.

#3 Yes, this is possible. You need to use date calculations. Take a look here: How do I add a variable number of days to a date? - the key here is that you can use the core language Date() object.

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...
Sep 01, 2017 0
try67 LATEST
Most Valuable Participant ,
Sep 01, 2017

Copy link to clipboard

Copied

1. Either way is possible. You can apply a calculation script to any field that requires one, or you can use a single field's calculation event to perform the calculations for all the fields in the file. The latter is especially convenient if you have a lot of fields and need to control their calculation order without messing around with the Fields Calculation Order list.

2. No. You need to use JS, but it has nothing to do with HTML. Most of the information you'll find about JS online pertains to using it in web-pages, and that won't work in a PDF file. A few good resources for using JS in Acrobat are:

http://www.adobe.com/devnet/acrobat.html

https://acrobatusers.com/tutorials/

http://www.pdfscripting.com/

The core syntax of JS for web and for PDFs is the same, so the books you books you bought might be useful, but the specific objects, methods and properties are very different.

By the way, note that for simple calculations you don't need JS at all. You can use the first two built-in options in the Calculate tab for things like a sum, product, average, etc.

3. That's possible, but manipulating date and time objects in JS is tricky. There are some good tutorials about this subject here:

https://acrobatusers.com/tutorials/working-with-date-and-time-in-acrobat-javascript

https://acrobatusers.com/tutorials/working-with-date-and-time-in-acrobat-javascript-part-2

https://acrobatusers.com/tutorials/working-with-date-and-time-in-acrobat-javascript-part-3

There's also a very good library developed by local expert Joel Geraci available here: http://practicalpdf.com/the-practicalpdf-date-library-for-adobe-acrobat/

http://practicalpdf.com/the-practicalpdf-date-library-for-adobe-acrobat/

And if you're interested I've developed a product that allows you to set up such calculations very easily and quickly, without having to write any code yourself (although you can check the source code and see how it works, of course): Custom-made Adobe Scripts: Acrobat -- Apply Automatic Date Calculation

It even lets you automatically ignore weekends and/or holidays when adding X days to a specific date, so only work days can be counted.

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...
Sep 01, 2017 0