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

Using radio buttons in a calculation

cjoverly
Registered: Feb 9 2010
Posts: 2

I am completely new to creating forms in Acrobat and to JavaScript. In my form I have two radio buttons, a field with a variable and a field to display the answer. I want to create a script that will calculate the following:

"If radio button 1 is selected, then multiply the value in the variable field times 120 and display the answer in the answer field. If radio button 2 is selected, then multiply the value in the variable field times 60 and display the answer in the answer field. If neither radio button is selected, then display zero in the answer field."

I have read a few articles on conditional statements and have written some code but am not quite there.

Thanks in advance for your ideas.

My Product Information:
Acrobat Standard 9.0, Windows
try67
Expert
Registered: Oct 30 2008
Posts: 2398
Here's my suggestion: Give the first radio button an export value of 120 and the second one 60.
I think that if you do that you don't need a script. You just set up the answer field's value as the product of the radio button and the variable field.
If that doesn't work, come back here and I'll give you the code to do it.

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

gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
When no item in a Radio Button group or Check Box group is selected the value for the group is 'Off' . If you are using the 'Field is the _____ of' Acrobat adjust for the value of 'Off'. But if you are using a custom calculation script, you need to test for the 'Off' value.

event.value = 0; // default value is no calculation performedif(this.getField('RadioButtonFieldName').value == 'Off') {// my calculation scriptevent.value = this.getField('VariableFieldName').value * this.getField('RadioButtonFieldName').value;} // end radio button not off

Note you can not use simplified field calculation method.

George Kaiser