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

Help whit acrobat form

shiva1976
Registered: Oct 28 2011
Posts: 2

Hello im a neewbie in acrobat and i need to create a form whit conditional execution for the "total" sum of the fields
 
the code i´ve created is this:
 
var ReqVal = this.getField("TRequerimento").value;
var Sum1 = this.getField("TP1").value;
var Sum2 = this.getField("TP2").value;
var Sum3 = this.getField("TP3").value;
var Sum4 = this.getField("TP4").value;
var Sum5 = this.getField("TP5").value;
var Sum6 = this.getField("TP6").value;
var SumT = Sum1 + Sum2 +Sum3 + Sum4 + Sum5 + Sum6;
if ( ((ReqVal == 1) || (Reqval == 5)) && (SumT < 100) )
event.value = 100;
else if ( (ReqVal == 2) && SumT < 200 )
event.value = 200;
else if ( ((ReqVal == 3) || (ReqVal == 4)) && (SumT < 150) )
event.value = 150;
else
event.value = SumT;
  
the problem is that it only calculate the first value (100) and don´t continue making the counts.
 
this script is inserted in the "total" text field
  
Can you help me thanks in advance
 
JM
   

My Product Information:
Acrobat Pro 10.1, Windows
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
Are there any errors in the Acrobat JavaScript Debugging Console?

Look carefully at the line that reads "if ( ((ReqVal == 1) || (Reqval == 5)) && (SumT < 100) )", where is "Reqval" declared?I would look at using the "switch" statement and not the "if" statement for complex decision statements.

George Kaiser

George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1875
Whenever you sum field values, make sure to explicitly convert them to numbers. If you don't, you will get string concatenation instead of numerical addition if any of the fields are blank, since an empty string is returned. You can do this using the unary + operator like this:

var Sum1 = +this.getField("TP1").value;

Do this for each field value that you retrieve.
shiva1976
Registered: Oct 28 2011
Posts: 2
Hello gkaiseril

thank you for your and George´s answers :)

The RecVal is declared in the first line:

var ReqVal = this.getField("TRequerimento").value;

im sorry its the first time im doing an acrobat form and can´t understand the javascript quite right

JM





gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
If you read the statement you will see you use "ReqVal" and "Reqval" variables, they are not the same variable but 2 different variables. Capitalization is important.

George Kaiser

redberry
Registered: Nov 1 2011
Posts: 1
I need a script for a pdf form with the following calculations:

[Field #1] Time In (start of day): 8:00 am
[Field #2] Time Out (end of day): 5:00 pm
[Field #3] Total hours: 9.00

[Field #4] Time Out (leave for lunch): 12:00 pm
[Field #5] Time In (back from lunch): 1:00 pm
[Field #6] Total hours: 1:00

[Field #8]: Total hours worked: 8:00

Any help in this maatter will be much appreciated.

K. Wiley
try67
Expert
Registered: Oct 30 2008
Posts: 2398
I created a tool that will automatically add the necessary scripts to calculate the time difference between sets of two fields, as well as calculate the total sum of those times, exactly for this purpose.
Have a look here: http://try67.blogspot.com/2011/03/acrobat-calculate-time-differences-in.php

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