10 Replies Latest reply on Sep 28, 2010 8:48 AM by jamezj7

# If calculation

Hi all,

"Field C" is dependant on a value being entered in either "Field A" or "Field B" but only one field can be chosen. So if "Field A" is 3 "Field B" must be 0 and vise vesa. This value is then multiplied by 0.18 and added to "Field C"

Currently I have a simplified field notation that requires me to manually enter a value of 0 for the non used field to complete the calculation. How can I make it so that when a value is entered in "Field A" a value of 0 is entered in to "Field B" automatically and vise versa?

Here is the field notation I have that is in "Field C", hopefully it makes sense.

(Field_A * 0.18) + (Field_B * 0.18)

Thanks!

• ###### 1. Re: If calculation

In the Validate event of field A, you could use code like:

// Custom Validate script

(function () {

// If field is blank, do nothing

if (event.value === "") return;

// If field is 0, do nothing

if (+event.value === 0) return;

// Set other field value to 0 if not blank or zero

getField("text2").value = 0;

})();

Replace "text2" with the name of the second field. You can add the same script to the second field's Validate event, but change the field name in the script.

• ###### 2. Re: If calculation

Thanks i will give it a try

• ###### 3. Re: If calculation

Hmm strange problem. It still doesn't work but then I copied the fields out of my document into a blank one and it worked fine. Then suddenly it stopped working. Now nothing works, all I did was save the new pdf after I seen it had worked.

All the scripts in each field are there, and correct. Sometimes also the fields reset and the script disappears in the calculate tab? what is going on? Is there some sort of bug in Acrobat? its really frustrating because one minute it works and if i open and close the pdf or even click another field sometimes that field stops working.

• ###### 4. Re: If calculation

Here is the file. All the scripting is there and currently on my PC it doesnt work. to start put a qty in the first field. It doesnt work but if you 0 that qty it then starts to work (sort of).

http://www.2shared.com/document/16z49FE_/Untitled.html?

• ###### 5. Re: If calculation

The code is designed to be used as the custom Validate script for a field, as mentioned. You're using it as a calculate script, which is wrong.

• ###### 6. Re: If calculation

how do i make it a custom Validate script?

dont worry found it

Message was edited by: jamezj7

• ###### 7. Re: If calculation

Ok its now working great but as mentioned in post 3 i am having weird issues with some of the other fields. It's not adding up all the fields correctly even though i have got the correct calculation script in there. Is there like a debugger or error report i can check because as far as i can tell it should all be working fine.

• ###### 8. Re: If calculation

Be sure to set the field calculation order to something that sense for your form.

• ###### 9. Re: If calculation

Also, you should set all of your calculated fields to read-only so a user is prevented from interacting with them.

• ###### 10. Re: If calculation

Yes thankyou I will do I figured out the problem it was my calculation order, the fields are all jumbled up therefore didnt calculate in the correct order.

Thanks again!