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

IF statements, checkboxes, and values

AlScott
Registered: Nov 2 2007
Posts: 123

I've hunted for a possible solution for this one. But no luck :(

I have 4 fields, let's call them A,B,C and D.

When checkbox1 is selected field A and B, not C & D are available, and when checkbox2, C and D are available, but not A & B.

Fields A,B,C and D get their values from other fields W,X,Y and Z

So I'd want A=W, B=X, C=Y, and D=Z.
(W,X,Y, and Z are fields on another part of the form)

Fields A,B,C,D,W,X,Y, and Z are all numeric values.

I hope this makes sense.

All contributions gratefully received.
thanks
Al

My Product Information:
Acrobat Pro 8.1.2, Windows
Dimitri
Expert
Registered: Nov 1 2005
Posts: 1389
Hi alscott,

This is all doable with scripting, but does require a bit of work and understanding of Acrobat JavaScript. Here is an article about showing and hiding fields based on check box or radio button selection-
http://www.acrobatusers.com/tech_corners/javascript_corner/tips/2006/show_hide_fields/

Try out some of the examples- then if you have specific problems with your script post again. It's helpful if you provide what error messages you get when you run your code in the JavaScript Console. If you don't know how to use the JavaScript Console here is an article explaining how to use it-
http://www.acrobatusers.com/tech_corners/javascript_corner/tips/2006/javascript_console/

Hope this helps,

Dimitri
WindJack Solutions
www.pdfscripting.com
www.windjack.com
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
When you say "available", what do you mean, exactly? Do you want to show/hide the fields, or make them read-only/not read-only? You say the fields should have the same values as the other fields, but do you want a user to be able to change their values as well? Are A, B, C, D calculated fields?

George
AlScott
Registered: Nov 2 2007
Posts: 123
Hi George,
The fields should be 'read-only'. They're there just so it is possible to see their values rather than scrolling through the document.
Appreciate the input.
Al
AlScott
Registered: Nov 2 2007
Posts: 123
Hi Dimitri
Yes Thom's info was great, now all is working wonderfully. Once I figured out what was happening!

I would like to do this with radio buttons. But I cant get this version to work. The buttons themselves are fine - but the JAVA line I've used is:

this.getField("RESPMONET").display = display.hidden;

Should there be a line before this. The radio buttons name is: FINDEC, and uses MOUSEUP as the action.

thanks again
Al
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4308
At the end of the article, Thom uses document level JavaScript's to enable and disable a text field based on which radio button of a pair is selected. This should help you. You want to look at the code for the "SimpleGrayEnable" code:

// Function to enable form fields
function EnableFormFieldFromGray(cFieldName)
{// First acquire the field that will be enabled
var oFld = this.getField(cFieldName)
// Next acquire the hidden field with the normal colors
var oNmlFld = this.getField("NormalColorsFld");
if(oFld)
{ // Make field interactive
oFld.readonly = false;
// Restore Normal Colors
oFld.fillColor = oNmlFld.fillColor;
oFld.borderColor = oNmlFld.borderColor;
oFld.textColor = oNmlFld.textColor;
}
}

// Function to disable form fields
function DisableFormFieldToGray(cFieldName)
{// First acquire the field that will be disabled
var oFld = this.getField(cFieldName)
if(oFld)
{ // Make field Read-Only
oFld.readonly = true;
// Set Grayed out colors
oFld.fillColor = ["G", 0.75];
oFld.borderColor = ["G", 2/3];
oFld.textColor = ["G", 0.5];
}
}

If you want to hide the fields change the section for setting the colors to hiding or displaying the field.

George Kaiser

AlScott
Registered: Nov 2 2007
Posts: 123
Great - all ok!!
Many thanks to gkaiseril, George J, Dimitri, not forgetting thomp!
A drink is owed to all !!
Al