Skip to main content
October 24, 2016
Question

need javascript help - show hidden fields under certain conditions

  • October 24, 2016
  • 3 replies
  • 437 views

looking for some help setting up a script to run on certain fields in a PDF form.

I have a form which information is currently filled in via a mail merge. One section allows for up to 4 different names to be displayed, along with a mailing address and verification checkbox. In any instance, the mailing address for each name is the same, and all pull from one cell in the data document, but the names are different. In most cases, a maximum of 2 names will display.

I am looking for a piece of javascript that I can run on the name/address/checkbox fields that does the following:

if the Name field has data (from the merge)

display the hidden Address field

and

display the hidden Checkbox field

Can someone help me construct this? While I understand the concept of what needs to happen here, I am not familiar enough with the coding to actually make it happen.

Thanks!

This topic has been closed for replies.

3 replies

October 25, 2016

Thanks both for your help. Reading through the posts, documentation and trying various combos of the script finally worked.

Of course, the kicker in all of this is that because the data merge was running in acrobat, the script would not override the merge data. I found a place to add the same script in the data merge settings and it worked perfectly.

Back on track!

Thanks again.

Inspiring
October 24, 2016

If the data merge is happening in Acrobat, the custom validation script in the Name field could be something like:

// Custom Validate script for Name field

(function () {

    getField("Address1").display = event.value ? display.visible : display.hidden;

    getField("Checkbox1").display = event.value ? display.visible : display.hidden;

})();

but replace those field names with the ones you're using.

Inspiring
October 24, 2016

See Disabling (graying-out) form fields with Acrobat 7 and 8 by Thom Parker. This is from 2007 but it still works with Acrobat DC. Some of the instructions have changed because of changes in the User Interface, UI.

October 24, 2016

This would work if the fields were being manually filled in, however, I need something to signal that if the name field has a "true" or "filled in" value, to open the address field and checkbox field

Inspiring
October 24, 2016

Do you understand the concept of a callable defined function?

I would add On Blur action or validation action to see if the name field's value length is greater than zero and if so then call

EnableFormFieldFromGray("Address Field Name Goes Here");

You may need to change the "Address Field Name Goes Here" to match the field name on your form.