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

Turn Off Radio Buttons

Terrill
Registered: May 4 2007
Posts: 14

Elsewhere on this site, I've seen people ask how to turn-off radio buttons once they've been clicked. And the usual answer is "You can't, so use Checkboxes instead."

Humm... try the following. It wll work with one, two, or two hundred Radio Buttons in a group, but I'll just do two. Adjust to your needs:

Given two radio buttons named "rad"; the first returns a value of "Yes" and the 2nd returns a value of "No"

In the Mouse Up() event of the 1st "rad" button, put the following:

if (this.getField("rad").OldValue == "Yes") {
    this.getField("rad").value = "Off";
}

In the Mouse Up() event of the 2nd "rad" button, put:

if (this.getField("rad").OldValue == "No") {
    this.getField("rad").value = "Off";
}

In the Mouse Down() event of [b]BOTH[/b] buttons, put:

this.getField("rad").OldValue = this.getField("rad").value;
Now, the radio buttons work as usual: select one, the other turns off. But, if you click a button that's currently selected, it turns off, leaving [b]both[/b] buttons [b]off[/b]!

This plays off (no pun intended) the fact that you can create/add any property you want on any object. In this case, we've created a new property named OldValue. Feel free to call it anything you want, like Fred, or something.

Enjoy!

-- Terrill --
"Those who can't, teach. Those who can't teach, manage."

pdftrainer
Expert
Registered: Dec 14 2005
Posts: 180
Thanks for this. It's always good to have more options.

Carl Young
www.pdfconference.com

A certified expert on Adobe Acrobat, Carl Young is an Adobe Acrobat and LiveCycle Designer trainer and consultant based in Phoenix. He is the producer of the [link=http://www.pdfconference.com/]PDF Conference[/link].

harvebj
Registered: Nov 14 2007
Posts: 7
Terrill,

I stumbled on your post after posting a similar question. I tried what you had posted and can't seem to get it to work. I'm using Adobe Designer 7.0. I gave two radio buttons the name "test". Both buttons are wrapped in the same redio group.

The mouse UP() event of the first button reads:

if (this.getField("Test").OldValue == "Yes") {
this.getField("Test").value = "Off";
}
The mouse UP() event of the 2nd button reads:

if (this.getField("Test").OldValue == "No") {
this.getField("Test").value = "Off";
}

Both mouse Down() events read:

this.getField("Test").OldValue = this.getField("Test").value;

What am i doing wrong???
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
I believe the code for the "Mouse Up" action should be testing the "OldValue" and not the value of the the given button. Realizing this and using JavaScript to obtain the field's name, the scripts for the "Mouse Up" and "Mouse Down" actions can be simplified to the following sclripts:

/*Mouse Down action:save the current value of the focused field*/this.getField(event.target.name).oldValue = this.getField(event.target.name).value;

/*Mouse Up action:if the saved value and current value of the focused field are equalthen turn "Off" the all the buttons or boxes with the same name*/if (this.getField(event.target.name).value == this.getField(event.target.name).oldValue)this.getField(event.target.name).value = "Off";

With the use of document level scripts, one could further simplify the code for the Radio or Check Boxes to calling just 2 functions.

George Kaiser