Skip to main content
buddycafe
Known Participant
April 15, 2016
Question

A single text-field that could display info from two hidden fields. One or the other but never both.

  • April 15, 2016
  • 12 replies
  • 1240 views

Hello,

I’m preparing a PDF that maps from a database. Could I get assistance in creating a script to do the following: A single text-field that could display info from two hidden fields. Depending on user selection, the Text Field displays one or the other. Perhaps a script that copies info from one hidden field if the second is null and visa versa?

I'm using Adobe Acrobat DC.

Thank you!

Eddie

This topic is closed to new replies. Start a new post to keep the conversation going.

12 replies

Inspiring
April 15, 2016

Depending on user selection, the Text Field displays one or the other.

User selection of what? Are you including some radio buttons or a dropdown for this?

buddycafe
buddycafeAuthor
Known Participant
April 15, 2016

In the user interface (prior to submitting PDF form), the user will select either box F1 or box F2. Where F1 and F2 pulls values from separate tables. In my PDF there is a single field that would display either F1 or F2 (never both because the interface wont allow it by design) upon submitting the form. I'm very novice but I took the path of creating two hidden fields that map to F1 and F2. With the goal (as note above) of displaying F1 or F2 to the non-hidden field when one of the hidden fields is null or visa versa.

Inspiring
April 15, 2016

OK, Karl's script will work as long as only one field will ever have a value, though it would be best to use the valueAsString field property instead of the value property:



if (f1 && f1.valueAsString != "") { 

    event.value = f1.valueAsString; 


Also, the script is a custom calculate script for the text field that displays the value.

Karl Heinz  Kremer
Community Expert
Community Expert
April 15, 2016

This is mostly standard JavaScript and has very little to do with Acrobat's JavaScript environment, so you may want to do yourself a favor and read a good introduction the core JavaScript langue. The following code will do what you specified - it will also use the value of Text1 in case both fields contain data:

var f1 = this.getField("Text1");

var f2 = this.getField("Text2");

if (f1 && f1.value != "") {

    event.value = f1.value;

}

else if (f2 && f2.value != "") {

    event.value = f2.value;

}

else {

    event.value = "";

}

buddycafe
buddycafeAuthor
Known Participant
April 15, 2016

This worked perfectly. Thank you Khkremer!   I'm new to JavaScript Language (and forums) but intend to read up so not to ask many questions.

Thanks,

Edgar