Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

Radio Button Help

Avatar

Level 1

I am worse than a nocive when it comes to creating scripts, so please forgive me in advance.

I am creating a form for my business and on the form the individual has 3 different elections that they can make through radio buttons.

For arguments sake, Options A, B, & C

If option B or C were elected I would like to create the option for another set of radio buttons (A-K) become visibile so that an alternate election can be made.

I have been informed that I need to write a script, but wouldnt have the slightest idea how to do it . Could someone provide me with a link or some insight.

Thanks

NP

9 Replies

Avatar

Former Community Member

I created a sample for you. The radioButtons are group into a RadioButtonList object (this makes it so you can only choose one item in the group). The code to control the presence of the other radioButtonList is on the change event of the A_C group. I have the D_K group set up as invisible by default and when the user selects B or C then the D_K group is made visible.

Paul

Avatar

Level 10

Hi,

Here is a sample: https://acrobat.com/#d=FXLq025O2C0aDMh9YqpH1g

If you select the first radio button group you will see the script in the click event.

It is basically testing the value of the first radio button group. The value of this group is set in the Object > Binding tab. I have set it to 1, 2, 3. But this could be anything, A, B, C or Apples, Bananas, Oranges. Just whatever you set the bound values as needs to be used in the if statement.

The second radio buttons are initially set to invisible in the Object > Field tab.

The if statement checks two conditions. The || is equivalent to 'OR'. So the script will make the second radio buttons visible if the first set's value is either 2 (Option B) or 3 (Option C).

Parallels Desktop2.png

I hope that helps,

Niall

... snap

Avatar

Level 1

Thank you both for your help. I will not attempt to do this on my own.

You assistance is greatly appreciated.

Avatar

Level 1

Thank you for your assistance. Apparently I am too novice to figure this out. I am trying to work it out in LiveCycle, but I think I

need to play around with it for several days before I'll even come close to understanding it.

Thanks

Avatar

Level 10

Hi,

Stick with it - it may take a bit of time, but just take it in small bites.

What version of LC Designer do you have? If you have LC Designer ES2, then there is a tool called Action Builder. This writes the script for you based on the logic that you provide. For example:

Parallels Desktop2.png

You should layout your workspace like the previous post screenshot. This way you can select objects and see the script editor (and any script in the events). Also you have access to the hierarchy on the left and useful tools on the right panels.

The language I used was javascript. It follows a strict syntax, which you need to follow. Luckily there are lots of books, guides and help on the forum.

If I break down the script for you:

JavaScriptWhat it does

if (this.rawValue == 2 || this.rawValue == 3)

This is a test. The script is in the radio button group, so 'this' is referring to itself, eg if this radio button group is equal to 2 (Option B) or if it is equal to 3 (Option C) then do something. The two tests are inside the brackets and are  separated by the OR syntax (||). The '.rawValue' is how you get the value of an object.

{

This marks the start of what action you want done if either tests are true.

secondChoice.presence = "visible";

The other radio button group is called "secondChoice" - you can see this in the hierarchy on the left. This line is telling Acrobat that if the test is true then set the presence of the object to visible. Object.Atribute = Value.

}

This closes the if true script. You could have several lines inside the curly brackets.

else

This tells Acrobat that if the test/statement was false, then execute the script in-between the following curly brackets.

{

Starting curly bracket for the else statement.

secondChoice.presence= "hidden";This is the line to be executed if the user selects Option A (which has a value of i).
}

Finishing curly bracket for the else statement.

Think of it as a set of building blocks. You are instructing Acrobat what to do depending on how the user fills in the form.

There is lots of help around - I would strongly recommend Creating Dynamic Forms with LC Designer by JP Terry - excellent!!

Also a book that doesn't deal with scripting at all but is very good is Forms that Workby Caroline Jarrett and Gerry Gaffney.

The Adobe PDF Forms Bible is okay, but mainly focuses on AcroForms.

Windjack Solutions have a subscription based service for solutions and scripts at http://www.pdfscripting.com. It has a lot of AcroForm script that can be amended to suit LC Designer and a growing library of LC Designer solutions.

Here are some online resources that you might find helpful:

http://www.adobe.com/go/learn_lc_scriptingBasics

http://www.adobe.com/go/learn_lc_scriptingReference

http://www.adobe.com/go/learn_lc_formCalc

http://www.adobe.com/devnet/livecycle/articles/Adobe_XML_Form_Object_Model_Refer ence.pdf

http://www.adobe.com/devnet/acrobat/pdfs/lc_migrating_acrobat_xmlform.pdf

And a very handy resource (and while it is for version 6 it is still very good because of the way it is laid out): http://partners.adobe.com/public/developer/en/tips/CalcScripts.pdf

There are some solutions on the Adobe Cookbooks:http://cookbooks.adobe.com/livecycle_designer_es

Lastly, check out the Developer's Network on http://www.adobe.com/devnet/livecycle/

Good luck,

Niall

Avatar

Level 1

I apologize for asking for your assistance again.

I have tried to figure this out and without actually posting the form, which contains sensitive work information, I have posted the fiels that I have created.

I have Radio_Button1 which contains that buttons named Member100, RO100, and Combo.

Then Radio_Button2 which has a series of boxes that relate to types of rollover plans.

The script I used was:

if

(this.rawValue == RO100 || this.rawValue == Combo)

{

Radio_Button2.presence

= "visible";

}

else

{

Radio_Button2.presence

= "hidden";

}

However, when I click RO100 or Combo it does not make available the rollover options in Radio_Button2.

I have provided a link to the document and if there is ANY insight that you can provide it would be greatly appreciated.

https://acrobat.com/#d=sFmaToqdfDALU8aO5WVtRw

Thanks

Nick

Avatar

Level 10

Hi Nick,

Here is the form back: https://acrobat.com/#d=ADtZDc8lSPWiAgH0Ip2EJw

Just a few things:

  • Save the form as Dynamic, because you are showing/hiding objects.
  • I would have quotations marks around the values you are testing in the if statement.

Lastly, in the File > Form Properties > Defaults tab, I would set the save script changes to Automatic, so that when the form is reopened the user will see the previous selections and script changes based on these selections:

Parallels Desktop1.png

I temporarily turn on the sunken square around the objects, so that I could see them.

Niall

Avatar

Level 1

WOW, Amazing!

All I needed was quotations, huh.

One other question, is there any way to allow someone to unclick the radio buttion? For example, if I click RO100 and elect one of the formerly hidden options if I change my election to Member100 that second scenario does not become invisible.

Sorry if I am annoying you with all this.

Avatar

Level 10

Hi,

Here is a sample: https://acrobat.com/#d=XGJNoujaSvn2X-7eJhi07A

This has thrown up an interesting problem. I have used this script many times (I think I got it originally from a post from Stefan Cameron).

The script is elegant, in that it captures the existing value of the radio button on mouseDown, stores it in the radio button group and then checks this against the new value on mouseUp. If the two are the same it clears the radio button.

When I scripted it into a new form, it didn't work.

It appears that the this.initValue is not working in Target v9.

Turns out when I lowered the Target version to v8 it worked. So there is a change, but I can't find anything in the XFA Specification.

So the example has two radio button groups. The first uses the original script (which works because the target version of the form is v8). and the second group which uses an invisible field to temporarily hold the original radio button value.

Hope that helps,

Niall