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

Need to convert excel formula to use with acrobat x

OutofMyWits
Registered: Jul 26 2011
Posts: 3
Answered

I have created a form in Acrobat X Pro. The form has several fields on it that a user would enter data in to get the cost of computer maintenance.
 
I need to write a javascript calculation for the Total1 field.
 
In Excel, I can write the formula like this: =IF(C6>0,SUM(849+(C6*10)),0) C6 is form field "Qty10 or Under", this number can be changed.
 
I need to add a base of $849 and then add it to form field "Qty10 or Under" with a multiplication of 10.
 
However, I am trying to utilize the simplified form notation to bring a calculation.
 
What I need to do bottom line is show a zero amount in the "Total1" field if the "Qty_10_or_under" field is at zero. Then I need to have the "total1" field show $849 if someone puts "1" in the "Qty10_or_under" field. "2" would equal $859, and so on.
 
What I have right now is this: (Qty10_or_Under>0,(Qty10_or_Under*10-10)+(849)) Using that formula, when I enter a "0" in the "Qty_10_or_under" field, I get $839. "2" in the "Qty_10_or_under" shows $859.00 as it should.
 
I just need to know how to make it to where I put a "0" in the field that I show a zero amount in the "Total1" field.
 
I am not familiar with using java script for the customized calculation script so I am trying to use the simplified.
If anyone can show me how to do the custom script it would be greatly appreciated.
 
Can anyone assist with this on Acrobat X?
 
Thanks!

My Product Information:
Acrobat Pro 10.0, Windows
George_Johnson
Online
Expert
Registered: Jul 6 2008
Posts: 1875
You can use the following as the custom calculation script for the Total1 field:

  1. (function () {
  2.  
  3. // Get the field value, convert to a number
  4. var v = +getField("Qty10_or_under").value;
  5.  
  6. // Set this field's value
  7. if (v > 0) {
  8. event.value = 849 + v * 10 - 10;
  9. } else {
  10. event.value = 0;
  11. }
  12.  
  13. })();
The first and last lines are not necessary, but prevent the unnecessary creation of document-global variables, which is a good thing. This can be simplified to just:

  1. (function () {
  2.  
  3. // Get the field value, convert to a number
  4. var v = +getField("Qty10_or_under").value;
  5.  
  6. // Set this field's value
  7. event.value = v > 0 ? 839 + v * 10 : 0;
  8.  
  9. })();
OutofMyWits
Registered: Jul 26 2011
Posts: 3
George, Thank you very much for the quick reply. I have been racking my brain on this.
I tried this variation and for some reason it remains at 859 regardless of what number I place in the "Qty10_or_under" field.
What I need to be able to have is when the "Qty10_or_under" field is at 0, the "Total1" (where I run the script) field shows "0"
When I put a "1" in the "Qty10_or_under" field it would show 849, 2 would be 859, so on.
I really do appreciate the help you have provided thus far.
Thank you!
George_Johnson
Online
Expert
Registered: Jul 6 2008
Posts: 1875
The code works fine for me. Are you creating your form in Acrobat or LiveCycle Designer? This will not work for a Designer (XFA) form. If Acrobat, do you see any errors in the JavaScript console (Ctrl+J)? If so, what is the exact text?
OutofMyWits
Registered: Jul 26 2011
Posts: 3
Accepted Answer
I use Acrobat X Pro.
I am so Sorry George, You are the best! I figured out that I did a typo on the form field. Duh, live and learn.