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

Visable/Hidden fields with calculations

lneib
Registered: Nov 16 2011
Posts: 3

I am a new to creating PDF forms and I am workinn on this form for a non-profit organization I do some work with. Here is my problem. The form is created except I have set up a radio button so that users can check to tell me wether they are a 'youth' or 'adult' depending on what they pick I have acrobat make a hidden field visable and it will show the price. Depending on if they pick youth or adult the prce is the defauly value so it naturally becomes visable. I also have field that is supposed to calculate the total cost of the what they are supposed to write the chack with. When I set up the calculation field wit hthe sum it calculates the price of both youth and adult wether they are hidden of visable and I want the calculation price based only visable fields. Can someone help me with the code for this?
 
thanks
 

My Product Information:
Acrobat Pro 10.1, Windows
try67
Expert
Registered: Oct 30 2008
Posts: 2398
You need to do the entire calculation using a script. It would be something like this:
var price = this.getField("age").value=="youth" ? 20 : 30;
event.value = price * this.getField("sum").value;

(I'm assuming here that the radio group is called "age", the sum field is called "sum" and that the prices are fixed. If they prices come from a field, replace the hard-coded numbers with getField("").value statements)

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

lneib
Registered: Nov 16 2011
Posts: 3
LOL, the radio group is called 'age' and the calculated field is call "total' when you click on the youth radio button makes the 'youth' field visable from hidden and when you click on the adult radio button the 'adult' field becomes visable. the prices are fixed but I am not pulling them from a table they are just the default value in the text field. I am sorry but i do not unserstand the last line in your comment 'replace the hard-coded numbers with getField("").value statements' where would the price value come from?
try67
Expert
Registered: Oct 30 2008
Posts: 2398
If they are fixed they you can ignore that.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

lneib
Registered: Nov 16 2011
Posts: 3
now I am even more confused and I don't even know what question to ask. becasue each field has a default value the 'total' always gives me the same price whether the field is visable or hidden. I only want the visable field to be calculated.
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
How are you toggling the field visible or hidden?

Why not just set the field to a null value.

// null the field
event.value = "";
var price = this.getField("age").value=="youth" ? 20 : 30;
// only compute field if its value is not "Off"
if(this.getField("age").value != "Off") {
event.value = price * this.getField("sum").value;
}

You can even use the "Custom validation Script" to suppress zero values, so you would not need to hide the field if its value is zero.

George Kaiser