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

PDF Forms - Need a Custom Calculation Script

gsolorio3
Registered: Dec 10 2010
Posts: 14
Answered

I'm able to complete the PDF form. But I feel that I can simplied this part as well.
 
On one field I am calculating a percentage. I call this field PercentTermEnroll. This is calculated based on the number a student is enrolled divided by the total number of days in a term. This is working just fine.
But I have the user entering a dollar amount in field T_DSL (Total Award Received). In another field called R_DSL (Revised Total Award) I am basically doing a multiplication of two fields:
 
T_DSL*PercentTermEnroll
 
So if I enter $1,000 under field T_DSL and the percent is 9.6%, the revised total award (R_DSL) is $96
 
R_DSL = T_DSL*PercentTermEnroll
 
R_DSL = 1000*9.6% = 1000*0.096 = 96
 
But what I want to do is that if the percent is greater than 60.1%, the Revised Total Award (R_DSL) must be zero.
 
I basically put on the PDF form a note, that if the percent was greater than 60.1% to stop and not complete the form. But we may have students who don't read the form in its entirely and they will fill out the form. So instead of giving them a wrong value, I would like a script that would put a zero if the percent was greater than 60.1%.
 
Thank you! .

My Product Information:
Acrobat Pro 10.0, Windows
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
Accepted Answer
Try this:

// Custom Calculate script
(function () {

// Get the field values, as numbers
var v1 = +getField("T_DSL").value;
var v2 = +getField("Percent_Term_Enroll").value;

// Set this field value
event.value = (v2 > 0.601) ? 0 : v1 * v2;})();
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
The forum software mangle it again. The last line should be separated to two, so that the last line is:


})();



gsolorio3
Registered: Dec 10 2010
Posts: 14
Thank you again, it worked. After adding the change you suggested, it did mess up another field. But I was able to use the same script you sent to me and simply had to add another variable (v3):

// Custom Calculate script
(function () {

// Get the field values, as numbers
var v1 = +getField("T_DSL").value;
var v2 = +getField("PercentTermEnroll").value;
var v3 = +getField("T_DSL").value;

// Set this field value
event.value = (v2 > 0.601) ? 0 : v3 - (v1 * v2);})();Thanks so much