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

Form if than else calculation

mgharris
Registered: Nov 30 2008
Posts: 5

OK, this has got me stumped and I've not really been able to find the answer anywhere.

In summary, I have a petty cash form where users will enter in the value of a transaction. The user will select a radio button (GSTRowX, yes value = 1, no value = 0) to indicate if GST is acceptable.

The resulting value for the net and GST columns is calculated based on if GST is acceptable. Eg:

if (GSTRowX == 1) then
 NetX = GrossRowX / 11 * 10
else
 NetX = GrossRowX
endif

I can get the values calculated using simplified field notation without a problem, it's when I go to do the if/then/else statement I get stuck.

So, here's my questions:

1) What would be the correct way to write the custom calculation script to acheive the desired result?
2) Where should the custom calculation code be run at? Should it be when a radio button in GSTRowX is selected or changed, or can the calculation be applied to NetX?
3) If the calculation field is applied to NetX, does it automatically update when the value of the radiobutton GSTRowX is switched?

All help, assistance, pointing of fingers and brickbats greatly appreciated.

Thanks in advance,

Michael Harris

thomp
Expert
Registered: Feb 15 2006
Posts: 4411
First, is this an AcroForm or a LiveCycle form? I'll assume it's an AcroForm since you mentioned Simplified Field Notation.

Second, the programming language used to script PDF forms is JavaScript. You'll find more info in my signature block.

And last, read this article:
http://www.acrobatusers.com/tutorials/2006/form_calculations

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

mgharris
Registered: Nov 30 2008
Posts: 5
Thanks for taking the time to reply, but despite looking through all the resources available (including the resources you linked to) I'm yet to find my answer. This is because I either don't know what specifically I'm looking for, can't find any examples of how to do this, or just stupid (unlikely, but not out of the question).

If anyone can point me closer to the question it would be greatly appreciated.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
You never answered the question about AcroForm or LiveCycle. You see, the exact solution to your issue depends on the answer.

So did you read the article? It explains where to enter the script and the proper syntax for accessing field values and setting a calculation result. Complete with pictures and an example download.

My intention was to give you the tools you needed to find the information. If you really had done even a tiny bit of research you'd have found out that calculation scripts are called any time any field on the form changes. You also would have found endless examples of JavaScript syntax in articles and sample downloads right here on this site. Including "if" statments, which are problem the most comonly used control construct.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
As noted you are trying to use LiveCycle Designer's FormCalc syntax and state you are using Acobat AcroForms which only uses Acrobat JavaScript. These products' scripting languages are [b]not[/b] interchangalbe.

Please clearify which program you are using.

Are you getting any error messages on Acrobat's JavaScript console? If so, please post the full error message.

You can not use any program flow control statements, can not use any object propterty, can not use any object method. etc. Also field names need to very simple, no dots. no spaces.

If you are using Acrobat, then you need to write a 'Custom calculation script'. This is done in using the Acrobat JavaScript for [url=http://www.adobe.com/devnet/acrobat/javascript.php]Acrobat's JavaScript extensions[/url] of [url=https://developer.mozilla.org/En/JavaScript]Mozilla JavaScript[/url] .

In Acrobat the value of an unchecked check box or radio button is the character string "Off" and the 'Export' value of the field 'widget', individual field in an exlclusionairy group. when checked.

George Kaiser