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

Form Functions

claramitsahne
Registered: Nov 10 2008
Posts: 31
Answered

Hi there,
I'm creating my first acrobat form and I'm having some difficulties achieving the clients requests. (In on a mac and using Acrobat professional 8). I have designed the form in indesign and applied the fields in acrobat.

This form is for keeping track of financial records.

The form must perform a few simple calculations
• a number is typed into field 'a'
• the user clicks a 'calculate' button and the number is divided by 52
• the answer pops up in field 'b' without changing the number in field 'a'

I'm new to this and i have no experience with java scripts!
My deadline is fast approaching so any help would be greatly appreciated.
Thanks in advance
Claire

gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
Both Acrobat Forms and LiveCycle Designer perform automatic calculations as data is inserted, so in general there is no need for a "Calculation" button. And if you do want the auto calculation feature, you need to explicitly turn it off by a script.

Have you looked at the eSeminars on demand on the AUC home page? There are eSeninars for Acrobat and LiveCycle Designer created forms.

George Kaiser

claramitsahne
Registered: Nov 10 2008
Posts: 31
The client has requested that the results would only appear when a button is clicked!
I'll check out the eSeminars now....
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
An alternative to using a Calculation script in field "b" is to use a Validation script in field "a". The Validation script would take the value entered, divide it by 52, and place the result in field "b". I often use this approach, mostly of avoid performance issues that can crop up when a lot of calculated fields are used. Here is an example custom Validation script that you can use in field "a":

// Get a reference to field bvar f2 = getField("b"); // If this field is not blankif (event.value !== "") { // Perform the calculation and set the value of field "b" to resultf2.value = +event.value / 52; } else { // If no entry was made, blank field bf2.value = ""; }

You would have to replace "b" in the code above with the actual name of your field.

If you really want to use a button, the code, which you would place in the button's Mouse Up event, could look something like:

// Get a reference to field bvar f2 = getField("b"); // Get value of field avar v1 = getField("a").value; // If the field is not blank...if (v1 !== "") { // Perform the calculation and set the value of field "b" to resultf2.value = +v1 / 52; } else { // If no entry was made, blank field bf2.value = ""; }

Finally, if you want to place the code as the custom calculation script of field "b", the code could look something like:

// Get value of field avar v1 = getField("a").value; // If the field is not blank...    if (v1 !== "") { // Perform the calculation and set the value of this field to resultevent.value = +v1 / 52; } else { // If no entry was made, blank this fieldevent.value = ""; }

Note the code changes slightly when used in the different situations. It uses the "+" operator to explicitly convert to a number. This is not strictly necessary in this particular situation since JavaScript will automatically do the conversion, but it's a good habit to get into when doing numerical calculation as a measure to avoid bugs. Also, note that all of the code above assumes field "a" has a numeric Format category. In other words, it assumes the field value is a valid number, unless it's blank. You'd otherwise have to add code to check that the field value is a number, as opposed to letters, etc. If a field has a numeric Format category, it is not possible to enter a non-numeric value (other than blank).

George
claramitsahne
Registered: Nov 10 2008
Posts: 31
Oh my God!! I cannot thank you enough! It works! Such a relief.
You are a life saver George. I really appreciate your help.
:)
susanpeirce
Registered: Jan 21 2008
Posts: 5
Thankyou George.
I have spent about 3 days going through the forums looking for a solution to this.
I posted a question (after 2 days of looking), but did not get a response.

I have been pulling my hair out because I could not complete the form.
So - thanks again.