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

New to acrobat scripting, need help with custom calculation!!

KKlemmer
Registered: May 11 2011
Posts: 7

Hello,
 
I am what most people would consider a "noob" to scripting. I am trying to create a Form in Acrobat, and do a custom calculation script. Just wondering if this is possible; I would like to have Text B output "Pass" if Text A is < 50 and output "Fail" if it is greater than or equal to 50. Any help would be greatly appreciated.
 
Regards,
 
Kyle

My Product Information:
Acrobat Pro 8.2.3, Windows
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
Sure it's possible. Assuming the "Text A" is a numeric field, the custom Calculate script for "Text B" could be:

  1. (function () {
  2.  
  3. // get the field value, as a number
  4. var v = +getField("Text A").value;
  5.  
  6. // Set this field value
  7. event.value = v < 50 ? "Fail" : "Pass";
  8.  
  9. })();
Replace "Text A" with the actual name of the field, if it's not really that.
KKlemmer
Registered: May 11 2011
Posts: 7
Hi George,

Thanks for the help, it seems as if it works, and then as soon as I save it, close the file, re-open it, it stops working. Any ideas what may be happening?
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
Where exactly did you place the code?
KKlemmer
Registered: May 11 2011
Posts: 7
I changed some of the code. Originally I said if Text A < 50 then fail, I ment if Text A >= 50 then fail. I also changed Text A to Text30, and Text B to Text40 to better suit my formIn "Text40" under Calculate tab - custom calculation script. Here is what the code currently looks like:

(function () {

var v = +getField("Text30").value;

event.value = v >= 50 ? "Fail" : "Pass";})();
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
It works for me. Do you see any errors reported in the JavaScript console (Ctrl+J)?
KKlemmer
Registered: May 11 2011
Posts: 7
No errors in the JavaScript console.
KKlemmer
Registered: May 11 2011
Posts: 7
I really appreciate your help with my scripting issues. I was wondering if you would like a copy of the form to see if I am missing anything? One thing I should mention, I have two text fields that I enter numbers, then another text field that calculates the difference, then another that converts to absolute value, then the absolute value is used in the custom script you provided me.
KKlemmer
Registered: May 11 2011
Posts: 7
I really appreciate your help with my scripting issues. I was wondering if you would like a copy of the form to see if I am missing anything? One thing I should mention, I have two text fields that I enter numbers, then another text field that calculates the difference, then another that converts to absolute value, then the absolute value is used in the custom script you provided me.
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
I'd be happy to take a look, but before you do that make sure that the field calculation order is correct for your form. I'm not sure what menu items you'd select in Acrobat 8 to do this, but if you don't know how, check out Acrobat's help doc. Note that this is not the same thing as the tab order, which some folks confuse it with.
KKlemmer
Registered: May 11 2011
Posts: 7
So I set the field calculation order, tested ok, then saved, closed and re-opened the file, and it wouldnt work. I went back to set field calculation order, and only 2/6 fields showed up, once I go in to the each individual "custom calculation script" and changed the text a little (for example, i would change +get to this.get, and it would work, then change back to +get and it would work) and it reset. It then showed up on the field calc order, and consequently the form calculations began functioning again.