Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Text variables with javascript?

Community Beginner ,
Jul 24, 2019 Jul 24, 2019

Hi all,

I'm looking for an answer if something I'm proposing is possible using javascript (or something else entirely). I'm looking to create a PDF form but have 'First name' and 'Surname' fields on the cover, but within the document variable text fields that populate with the 'First name' on other pages. Is this possible, or would this not be javascript at all?

So for example:

Page 1

First name: Becky

Surname: Smith

Page 3

Running header: "<Becky>'s workbook"

Page 5

Body copy: "<Becky>, here is your chance to answer some questions."

Any advice greatly appreciated!

TOPICS
Acrobat SDK and JavaScript
1.4K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jul 24, 2019 Jul 24, 2019

For that you will need to use fields with unique names and a simple script to copy the value other.

For example, if the editable field is called "Name" and the copy is called "NameCopy", use the following code as the custom calculation script of the latter:

event.value = this.getField("Name").valueAsString;

Then you can set the copy field to be read-only and then user won't be able to edit it.

Note, though, that the text in this field will not "re-flow" the rest of the sentence. To do that the entir

...
Translate
Community Expert ,
Jul 24, 2019 Jul 24, 2019

You can copy and paste the fields from the first page to the other pages, and they'll all have the same value automatically.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 24, 2019 Jul 24, 2019

Thanks for the speedy response. That does work to some degree, however this means the form field is visible on the populated areas. I'm looking for these to look like part of the same sentence and not an editable area, as such.

Is there a way around that?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 24, 2019 Jul 24, 2019

For that you will need to use fields with unique names and a simple script to copy the value other.

For example, if the editable field is called "Name" and the copy is called "NameCopy", use the following code as the custom calculation script of the latter:

event.value = this.getField("Name").valueAsString;

Then you can set the copy field to be read-only and then user won't be able to edit it.

Note, though, that the text in this field will not "re-flow" the rest of the sentence. To do that the entire text needs to be a part of the same field.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 24, 2019 Jul 24, 2019

Wow! Thank you so much, that really does exactly what I needed!

try67  wrote

Note, though, that the text in this field will not "re-flow" the rest of the sentence. To do that the entire text needs to be a part of the same field.

How would I include the rest of the text into the field as well?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 24, 2019 Jul 24, 2019

Use something like this:

event.value = this.getField("Name").valueAsString + " other text ";

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 24, 2019 Jul 24, 2019
LATEST

Amazing guys! Thank you both very much!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 24, 2019 Jul 24, 2019

Use a field for the whole header and a field for the whole body.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines