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

Evaluating Multiple Sets of Radio Buttons With JavaScript

WayneX
Registered: Mar 2 2010
Posts: 6
Answered

I am brand new to JavaScript, but not to Acrobat forms.
Here's the deal. I have a form with 3 yes/no questions. I am using radio buttons (radio1, radio2, radio3). My users may select the yes/no answers in any order (not my call - customer's call). I need to trigger an event -- make a hidden text box visible -- only of the answer is 'yes' to all three questions.

I started out evaluating all three buttons every time a 'yes' answer is selected on each radio button. This would fail on the first two 'yes' answers and succed on the third 'yes' regardless of the order of the entries.

I cannot make it work with JavaScript so far. Here is what I tried:

If
(this.btneAuth1.value=="eAuth1Yes" && this.btneAuth2.value=="eAuth2Yes" && this.btneAuth3.value=="eAuth3Yes")

{eAuthBanner.hidden = false}
else

{eAuthBanner.hidden = true}

Acrobat accepts it without syntax errors, but it just doesn't work.

Help!!!

-Thanks

My Product Information:
Acrobat Pro 9.2, Windows
try67
Expert
Registered: Oct 30 2008
Posts: 2398
- You're not accessing the fields correctly.
- You're not hiding the fields correctly.

Have a look here: http://www.adobe.com/devnet/acrobat/javascript.php
Look especially at the Field object and the Document object's method getField.

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

WayneX
Registered: Mar 2 2010
Posts: 6
try67,

Thanks, but I am a JavaScript novice. I could not understand most of the stuff I read in the references you provided.

Could you just tell me how to access the fields correctly?
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Let's back up a little bit. Was this form created in Acrobat or LiveCycle Designer?

Once this is known then we can give you the correct syntax.

BTW, the correct place to perform this action, hiding and showing the banner fields, is in the calculation event for "eAuthBanner".

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

WayneW
Registered: Mar 2 2010
Posts: 2
thomp,

I created the form in Acrobat. I set the mouse up action on each radio button to run a Javasript and you saw the Java Script I wrote.

-Thanx for the quick response
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
To get the value of a field use this code:

this.getField("btneAuth1).value;

So your script is actually pretty close, just missing some details. If you were to place the hide/show code in the calculation event of the banner field, instead of the MouseUp event of the radio buttons, it would look like this;
event.target.hidden = !( (this.getField("btneAuth1).value=="eAuth1Yes") && (...) )
The calculation event is called anytime the user changes a field so all your code is in one place and activated at the right time.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

WayneX
Registered: Mar 2 2010
Posts: 6
thomp,

Thanx a million.

Does the exclamation point following the equal sign make this "not equal"? The reason I ask is the initial form has this text box hidden and I only want it to show if 'yes' is selected on all three sets of radio buttons.

You can just tell I'm a nervous novice cantcha :-)
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Yes, the "!" is the logical inversion operation, commonly refered to as a "bang". If all three are set to yes, given that your button export values are set correctly, then the result of the logical AND, "&&", will be TRUE. The bang will invert this to FALSE which makes the field visible. Otherwise the field's hidden property will be set to "TRUE".Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

try67
Expert
Registered: Oct 30 2008
Posts: 2398
One small note. The hidden property has been superseded by the display property.

To hide a field, use: .display = display.hidden;
To show a field, use: .display = display.visible;

(If you do make the switch, you will also need to adjust the code provided by Thom)

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

WayneX
Registered: Mar 2 2010
Posts: 6
thomp,

"less filling, tastes great!!!"

Thanks again.