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

Convertiing Excel Formula to Adobe Java Script (Help)

token678
Registered: Nov 2 2011
Posts: 5

Hi,
 
I know very little about JavaScript, and am on a fast learning curve.
 
I converted an Excel Form (2003) to an Adobe Form (Adobe x Pro).
I have completed the simple JavaScript additions with the: Text Field Properties, Calculate.
 
After seemingly endless hours on the internet, and going through books, I cannot find a definitive answer to my problem.
 
To convert (2) Excel calculation/formula into JavaScript
 
Number 1
=IF(D14>0,D14/D13,0%)
and Function: IF (logical_test, [value_if_true], [value_ if_false])
 
Number 2
=(C13*80%)-C14
 
With the above JavaScript equivalents, I would be able to complete other calculations.
 
I would appreciate any help with this.

Token678

My Product Information:
Acrobat Pro 10.1, Windows
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
You will have to write custom JavaScript calculations.

Was your form created using LiveCycle Designer (XML) or Acrobat. Each program uses a different language and syntax.

LiveCycle Designer has a Scripting Reference under the Help menu.


George Kaiser

token678
Registered: Nov 2 2011
Posts: 5
Hi George,

Completed on Acrobat X Pro (not Live Cycle Designer)

Token678

try67
Expert
Registered: Oct 30 2008
Posts: 2398
To learn more about JS core functionalities and syntax: http://w3schools.com/js/default.asp
Specific Acrobat JS reference: http://www.adobe.com/devnet/acrobat/javascript.php
There are also many good tutorials about this subject on this website.

Number 1 (set the field as a percentage field):
  1. var d13 = this.getField("D13").value;
  2. var d14 = this.getField("D14").value;
  3. if (d14=="" || d13=="" || d13==0) {
  4. event.value = "";
  5. } else {
  6. if (d14>0) {
  7. event.value = d14/d13;
  8. } else event.value = 0;
  9. }
Number 2:
  1. var c13 = this.getField("C13").value;
  2. var c14 = this.getField("C14").value;
  3. if (c13=="" || c14=="") {
  4. event.value = "";
  5. } else event.value = (c13*0.8) - c14;

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

token678
Registered: Nov 2 2011
Posts: 5
Dear try67,

This is a terrific outcome , thank you for taking the time and effort to resolve my issue.
I will log onto the websites you suggested to further my learning curve. And jump onto your scripts website as well.

Regarding my Form: I have many similar calculations to complete. I will tackle the job late tomorrow, and update you how it went.

Again thanks.

Token678

try67
Expert
Registered: Oct 30 2008
Posts: 2398
Notice that the field names I've used are the names of the cells you've used in your Excel spreadsheet. If the names of your form fields in the PDF are different, then you should adjust that, or the script won't work.

Good luck!

- 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
Another thing to be aware of: unlike in Excel, in Acrobat the calculation order is not determined automatically. So if you have many calculated fields (and I'm assuming some of them use the values of other calculated fields), then you need to make sure the calculation order is correct. To do so go into Form Edit mode > Other Tasks > Edit Fields > Set Field Calculation Order...

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

token678
Registered: Nov 2 2011
Posts: 5
Noted. When I set up the Form perimeters I ensured that the Excel spreadsheet Capitals and Numbers lined up.

When the additional calculations are completed, I understand that the Capitals and Numbers must coincide with the change of cell.

With the 2nd calculations they are in sets of 3 and the products also change.

I will take care.

Again thanks.

Token678

token678
Registered: Nov 2 2011
Posts: 5
To Forum,

Thanks Try6767. I followed your guide and (finally) have completed the JavaScript.
Much appreciated.

Token678