Expand my Community achievements bar.

Addressing Individual Radio Buttons with a Conditional Statement

Avatar

Level 2

Hello Everyone

Accounting for the possibility that I posted this in an incorrect forum previously, I am re-posting here with the hope that no forum rules are violated in doing so.

I don't know a lot about writing code, just basic things.  The last thing I touched was C++ while in college and that was over 10 years ago.  However, let's say I have a subform "FormA" that has a radio button object "Obj1" with four radio buttons R1, R2, R3, and R4.  Using Acrobat 8 and FORMCALC, is there a way to address each individual radio button in an IF/THEN statement?  For example, if R1 is selected, then display the number 1, if R2  is selected, display the number 2 and so on.  Of course, it is just my guess that these buttons are sub-components of a main object, I get errors when I try to refer to each sub-component.  Any help would most certainly be welcomed.

Thanks

Daryl

5 Replies

Avatar

Former Community Member

You can do it that way but typically the RadioButtons are in a RadioButtonList (this is what gives them their exclusivity). So instead of testing the individual button you woudl test the RadioButtonList. So using your example and if the RadioButtonList is what you call the RadioButtonObject:

if (conditionion you want to test){

     OBJ1.rawValue = value of the RadioButton you want to set

}

Note that in teh RadioButtonList Object if you click on the Object palette and choose teh Binding tab this will allow you to give each RadioButton on state a unique value (like 1,2,3,4). They can display whatever you want but the on state must be unique. Then you simply set the obj1 to have that on state and your button will be activated.

Hope that helps

Paul

Avatar

Level 2

Although this looks like Javascript, I'm sure the logic logic applies to FormCalc (the language I'm using in the form) and give this a try.  I guess that means using ELSEIF statements to test the entire RadioButtonList?

(......wonder how long it would take me to learn basic Javascript???.........)

Thanks for your recommendation!  I'll let you know how it works out!

Avatar

Level 2

Unfortunatley, my inexperience with this language and working with objects will become apparent b/c I am having problems with the syntax as you'll see below.

>The RadioButtonList name is "RObject1"

>The three individual radio buttons are named R1, R2 and R3 with values of 30, 60, 90 respectively

>A numeric field named NField1 is supposed to display which radio button is selected

>Using FormCalc, the following script was used:

          if (RObject1=30) then NField1=30 else Field1=0 endif

>I used "calculate" as the event and committed the changes.

The below error is generated:

Script failed (language is formcalc; context is xfa[0].form[o].form1[0]#subform[0].NField1[0])

script=if (Object1=30) then NField1=30 else Field1=0 endif

Error: syntax error near token'=' on line 1, column 12

Obviously, my supposing that RObject1 would take on the value of whatever button was selected does not seem to be the case or I am incorrectly addressing the object.

Thanks

Avatar

Former Community Member

if (RObject.rawValue == "30") then

     NField1.rawValue = 30

else

     Field1.rawValue = 0

endif

The = is an eqate one value to another the == is a comparison of one value to another. I think the radio button definition is a string so I put it in quotes ...if it is a numeric then remove the quotes.

Paul

Avatar

Level 2

LIke you said, the = and the == are two completely different animals and it's actually what I've been missing......for the past THREE DAYS!  It worked perfectly!  I CAN'T WAIT to get the two books I ordered this morning from Amazon on Javascript (so I can get away from FormCalc) and designing forms with LiveCycle.  Guess I'm getting old and have forgotten all this stuff from college.  

Thanks, for the advice and sticking with me on this Paul.  You have been a TREMENDOUS help!