Good morning ladies and gents,
I'm the process of converting a bunch of Word documents over to fillable PDFs.
The form I'm currently working on has checkboxes and radio buttons (along with several) text fields.
My question is this:
If the end-user marks a checkbox on one part of the form, I need it to disable the following five pairs of radio buttons.
I also need to implement this feature/script twice in the document.
I know this is possible, I'm just not sure how to go about it.
I've tried modifying several Javascript code segements found online, to no avail.
Any help would be greatly appreciated-- I can provide form names, screenshots of the documents and any other info upon request.
Thanks :]
I am using the Form Tools within Acrobat.
I'm reading page you referenced right now.
I was hoping someone would be able to help me code this out...
The checkbox name is 'Supplier_Info - DDC_None', the default export value is 'Yes'.
The radio buttons to be disabled upon check are named 'Q19', 'Q20', 'Q21', 'Q22', and 'Q23'.
So my code should look something like:
varcAgree =this.getField("Supplier_Info - DDC_None").value;
if( cAgree =="Yes") [insert code for disabling the radio buttons here];
But that part is essentially just the code that looks for the status (unchecked [off] / checked [yes]) of that checkbox, right?
You need to access each group of radio buttons by their form field name and set the 'readionly" property to 'true".
Since you need to process a block of commands, use the curly brackets to mark the block of code.
You also need to process the form fields when the value is not "Yes".
var cAgree = this.getField("Supplier_Info - DDC_None").value;
if( cAgree == "Yes" ) {
// make the following radio boxes read only
var oField = this.getField("RadioBox 1");
oField.readonly = true;
oField = this.getField("RadioBox 2");
oField.readonly = true;
oField = this.getField("RadioBox 3");
oField.readonly = true;
} else {
// make radio buttons RW
var oField = this.getField("RadioBox 1");
oField.readonly = false;
oField = this.getField("RadioBox 2");
oField.readonly = false;
oField = this.getField("RadioBox 3");
oField.readonly = false;
} // end process radio buttons
Awesome, thank you for your time and help.
So from the 'Tools' panel, I select 'JavaScript' and then 'Document JavaScripts'.
Then, I add an entry and insert the following code:
function disable_radio_buttons_DDC()
{
var cAgree = this.getField("Supplier_Info - DDC_None").value;
if( cAgree == "Yes" ) {
// make the following radio boxes read only
var oField = this.getField("Q19");
oField.readonly = true;
oField = this.getField("Q20");
oField.readonly = true;
oField = this.getField("Q21");
oField.readonly = true;
oField = this.getField("Q22");
oField.readonly = true;
oField = this.getField("Q23");
oField.readonly = true;
} else {
// make radio buttons RW
var oField = this.getField("Q19");
oField.readonly = false;
oField = this.getField("Q20");
oField.readonly = false;
oField = this.getField("Q21");
oField.readonly = false;
oField = this.getField("Q22");
oField.readonly = false;
oField = this.getField("Q23");
oField.readonly = false;
} // end process radio buttons
}
But there must be more to it or I'm doing something wrong because it doesn't seem to work...
Hi Kelso
I have the same problem as you have had. I have tried to put in the code as above in my form. I don't know much about scripting, so where to put the OnMouseUp-event in the code I have no clue! None of the places where I tried did work.
Can you show me in your code how you added the button name to the event?
Thanks
-Charlotte
Hi again GKaiseril
So now I'm trying once more - and without my personal expert - to make a radio button exclusion. And I can't get it to do what I want!
I have two sets of radio buttons: "RB1" and "RB2".
In RB1 there is five possible choices: "C1-1", "C1-2", "C1-3", "C1-4", "C1-5".
In RB2 there is four possible choices: "C2-1", "C2-2", "C2-3", "C2-4".
(In my form they have different names, but this to make it easy.)
So, what I need is to make C1-4 disable C2-4.
If I type in what you learned Kelso:
function Disable_C2-4()
{
var cAgree = this.getField("RB1").value;
if( cAgree == "C1-4")
{
// make the following radio boxes read only
var oField = this.getField("C2-4");
oField.readonly = true;
oField.value = "Off";
}
else
{
// make radio buttons RW
var oField = this.getField("C2-4");
oField.readonly = false;
} // end process radio buttons
}
I get this error in the console:
TypeError: oField is null
12:Field:Mouse Up
I can only make it work if I switch out "C2-4" with the whole set: "RB2". But then all the radio buttons in RB2 is made read only, and that isn't what I want.
How can I access only one of the button choices?
I hope you can help me since I need this type of function on several other forms.
I may be wrong here, so hopefully GK comes back, but I believe you can only set it to call out a group. In this case, you're seeing it work when you specify 'RB2', but not when you call out specific choices within that group.
This sounds like a very specific function-- are you sure two sets of radio buttons is the best approach? Is there any instance in which you could utilise a check box instead of radio buttons?
I just want to make sure you're taking the right approach here before someone hops in to help you troubleshoot the code.
RB1 is a form, and the radio buttons (C1-1 through C1-5) are a subset of that form.
I believe the Javascript used in my form allows you to set a form (and all elements within it) as read-only.
What you are attempting to do is set only a portion of the form (specifically, button C2-4).
This would explain why it works when you set the it to "disable" all of RB2, but not a portion (C2-4) of the form named 'RB2'.
You may be able to get this to work by making C1-4 and C2-4 their own radio button forms, but I believe that will cost you the functionality of having them considered part of the RB1 or RB2 group... which means they'd no longer function as they should.
No, that wouldn't work out right.
I really don't understand if it's not possible to call just one option of the radio buttons...
But I guess I will have to settle with an explaining text saying that the choice is not an option with the other choice - and hope that people will read it!
Thank you for your time, Kelso.
You can if you reference the "widget" of the check box or radio button, but this is very tricky and can be confusing.
North America
Europe, Middle East and Africa
Asia Pacific