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

javascripting for radio buttons

jpmeyer8116
Registered: Sep 29 2009
Posts: 12
Answered

I am having an issue with a set of 3 radio buttons. I have three radio buttons named rbCompanion, with export values of; A, U, and N/A

I also have a text field named txtCompanion. I am trying to write javascript so that if the N/A radio button is chosen the Text field will be grayed out and state N/A. If anything else is selected the text field will stay editable and trasparent. I can get the text box to gray out and state N/A. HOWEVER, if I select another radiobutton say the one that exports A, the text box remains grayed out and states N/A. Below is my script, I have this on all three radio buttons on mouse up. Any suggestions on what I could do will be greatly appreciated

var a = this.getField("rbCompanion")
var b = this.getField("txtCompanion")

if(a.value == "N/A")
{
b.fillColor = color.ltGray;
b.value = "N/A";
b.readonly = true;
}
else if(a.value == "A")
{
b.fillColor = transparent;
b.value = "";
b.readonly = false;
}
else if(a.value == "U")
{
b.fillColor = transparent;
b.value = "";
b.readonly = false;
}

try67
Expert
Registered: Oct 30 2008
Posts: 2399
First change the readonly state, and only then the other properties.

- 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: 4308
Have you checked the JavaScript debugging console for any errors?

With your script, I receive the error "transparent is not defined". To set a field to the 'transparent" color one need to use "color.transparent " or '["T"]'.

I would also look at using a document level function so each button need only call the function. This not only saves on the amount of data to cut and paste, but makes maintenance much easier as there is only one location at which to edit the code.

var a = this.getField("rbCompanion")var b = this.getField("txtCompanion") if(a.value == "N/A"){b.fillColor = color.ltGray;b.value = "N/A";b.readonly = true;}else if(a.value == "A"){b.fillColor = ["T"];b.value = "";b.readonly = false;}else if(a.value == "U"){b.fillColor = color.transparent;b.value = "";b.readonly = false;}

George Kaiser

jpmeyer8116
Registered: Sep 29 2009
Posts: 12
Corrected script to add "color." in front of transparent and it works! I think I was staring at this so long that I just didn't know I was missing that. I will also change this to a document level function as you have suggested. Thanks for the reality check!!

I corrected the above first and since this worked I did not try the other suggestion of putting my readonly statements before the others.

Thanks for all the suggestions and help.