I have a PDF form. For the sake of simplicity, Lets say I have 5 fields. 2 Are check boxes (IDs FSA1 and FSA2), 2 are text fields (IDs TotalClaimed1 and TotalClaimed2), and a text field (FSA_Total) which adds the number from TotalClaimed1 if FSA1 if checked, and also add TotalClaimed2 is FSA2 is checked.

My question is what I write in the "calculate custom script" box of the FSA_Total field: (I unsuccessfully tried)

if (FSA1.checked == 1) {

event.value += Totalclaimed1;

}

if (FSA2.checked == 1) {

event.value += Totalclaimed2

}

I can post the actual form I am working on, if you think that will help. Just let me know

OMGCarlos
—
2012-05-16T03:40:07Z —
#2

Yea, I might need to see the form because I'm not sure I think I understand what you need.

If you load it up, there are tons of fields and such - but to troubleshoot the issue, Lets focus on the first 2 lines of the claim form, and the box at the bottom displaying the FSA total.

The box at the bottom, FSA_Total, should show 0. If the box FSA1 is checked, it should add the total from the field TotalClaimed1. Additionally, if the box FSA2 is checked, it should add the total from the field TotalClaimed2.

(Once I can get that to work, modifying the code to apply to all 11 lines/4 benefits in the claim form should be relatively easy. )

In Adobe Acrobat X, if you double click on FSA_Tota, you get the "Text Field Properties" box. Under the "Calculate" tab, the third option is a custom calculation script.

This is the area where my JavaScript code is.

if (FSA1.checked == 1) {

event.value += Totalclaimed1;

}

if (FSA2.checked == 1) {

event.value += Totalclaimed2

}

Once you've had a chance to take a look at the PDF, if you are able to assist me with the code, I'll be incredibly greatful. (I just wish my company realized there is a difference between a graphic designer and a programmer!!!)

I'll be honest with you, I didn't know you could embed HTML into a PDF like this!

I actually meant the form code, that's my fault. I'm on a Mac and don't have Acrobat Reader, so I can see the form but not the code.

The code you copy+pasted looks like it should work (other than the fact that there's a missing ; after Totalclaimed2), but without knowing how "event" is set, how FSA1 is set, etc I can't really help out.

Know that if you want get the checked state of a checkbox with, say, ID "Test" this won't work:

if(Test.checked == 1)

You first need to do this:

Test = document.getElementByID('Test');
if(Test.checked == 1)

That would work.

Rennie_ben
—
2012-05-21T19:28:17Z —
#5

Hello OMGCarlos,

I took a look at the live JS page you mage. That was quite handy. I was trying to accomplish this without a calculate button - I am not sure if that's possible.

fsabox.value

But there is a problem with the code. Here is what I want to happen:If FSA1 is checked, add the value from TotalClaimed1 (var a) to the variable fsaboxANDIf FSA2 is checked, add the value from TotalClaimed2 (var b) to the variable fsabox

That is not what's happening though. Here is what's happening instead:If FSA1 is checked, add the value from TotalClaimed1 (var a) to the variable fsaboxBUTIf FSA2 is checked, add the value from TotalClaimed2 (var b) to the variable fsabox instead.

(If FSA2 is checked, fsabox only displays the amount from TotalClaimed2. It disregards the amount from TotalClaimed1, even if FSA1 is checked)

Can you see what in the code is causing it to behave like this?

Thanks

OMGCarlos
—
2012-05-21T19:36:04Z —
#6

You've got your operators flipped, should be:+=not=+

The former adds/concatenates to an existing number/string while the latter...does something weird.

Rennie_ben
—
2012-05-21T19:56:20Z —
#7

Flipping the operators caused "something weird" to happen.I changed the code, and here is what happened:

I checked FSA1, and put $10 in TotalClaimed1. FSA_Total correctly showed $10.When I check FSA2, FSA_Total instantly changes to $1010 (incorrect)If I put a figure like $50 into TotalClaimed2, FSA_Total changes to 10101050

So flipping the operators did not work.

I very much appreciate your quick replies and troubleshooting with code. I am sure its not easy!

Something is causing it to add every time the box is checked. Like the checking off of the box is what causes the addition.

Its almost reading the code as "When the box is checked, add the value to the total", so each time the box gets checked, it adds to the total again.and it should be "IF the box is checked, add the value to the total" so if there is a value in the field, and the box is checked, that value is passed on to the total; and if the box is not checked, the value is ignored.

Does this make sense?

OMGCarlos
—
2012-05-21T20:31:45Z —
#12

I can't really help you when you only keep showing me part of the code, just show me the entire function.

This entire time you still haven't told me what event is...

I'm guessing this is inside the Checkbox.onchange() event, but I don't know.

Rennie_ben
—
2012-05-21T20:34:47Z —
#13

I think JavaScript might function a bit differently in HTML than in a PDF document.In the PDF, I am selecting the FSA_Total field. In the properties box, there is a "calculate using javascript" button.That gives me a little window to put the JavaScript. The only thing in that window is: