7 Replies Latest reply on Oct 25, 2013 2:35 AM by try67

Best way to do calculation depending on drop down box selections

I have a timesheet set up that employees choose from two different drop down fields which department they worked in and which station they worked at for each start and end time section. What I am trying to do is have a summary table on the bottom of the timesheet that calculates the time spent for each combination.

The departments are N&S, P and A and our stations are WN, ZO, LR and FM so the summary table would look like this:

WNZOLRFM
N&S
P
A

I have three sections of start and end times with each one calculating their time in separate fields named M1, M2 and M3.  What I am trying to set up is an if statement for each cell in the summary table. For example:

If 'deptmonday1' = N&S and 'stationmonday1' = WN

then x = M1

and

if 'deptmonday2' = N&S and 'stationmonday2' = WN

then y = M2

and

if 'deptmonday3' = N&S and 'stationmonday3' = WN

then z = M3

so cell 'WNN&S' = x + y + z

Can someone help me with the scripting for my if statments or is there an easier way to figure this out? I am using Acrobat Pro.

• 1. Re: Best way to do calculation depending on drop down box selections

Custom calculation code for "WNN&S":

var x=0;

var y=0;

var z=0;

if (this.getField("deptmonday1").value=="N&S" && this.getField("stationmonday1").value=="WN")

x = Number(this.getField("M1").value);

if (this.getField("deptmonday2").value=="N&S" && this.getField("stationmonday2").value=="WN")

y = Number(this.getField("M2").value);

if (this.getField("deptmonday3").value=="N&S" && this.getField("stationmonday3").value=="WN")

z = Number(this.getField("M3").value);

event.value = x + y + z;

• 2. Re: Best way to do calculation depending on drop down box selections

Thank you so much! That worked!

• 3. Re: Best way to do calculation depending on drop down box selections

Gilad D (try67), how many variables can I include for the custom calculation code for "WNN&S"? I have 42 fields in a 2 week period for the timesheet (3 per day, 7 days a week x 2). Everytime I try to add a var a, var b, var c, var d, etc., it doesn't work. Is there a limit to how many I can have? I even tried splitting the weeks up seperately but 21 didn't work either. Please help. Thank you!

• 4. Re: Best way to do calculation depending on drop down box selections

There's no limit to the number of variables you can use... Are you getting any error messages?

• 5. Re: Best way to do calculation depending on drop down box selections

I'm not getting any error messages but my value equals zero.

• 6. Re: Best way to do calculation depending on drop down box selections

I figured out the problem. I had copied my script from Word and the dash changed and was not read correctly in Java. As soon as I changed them, it all worked. Thank you again!

• 7. Re: Best way to do calculation depending on drop down box selections

Never use Word for writing code. Use only a plain-text editor. I recommend Notepad++.