Text variables with javascript?

New Here ,
Jul 24, 2019

Copy link to clipboard

Copied

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!

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

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.

TOPICS
Acrobat SDK and JavaScript

Views

99

Likes

Translate

Translate

Report

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

Text variables with javascript?

New Here ,
Jul 24, 2019

Copy link to clipboard

Copied

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!

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

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.

TOPICS
Acrobat SDK and JavaScript

Views

100

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jul 24, 2019 0
Most Valuable Participant ,
Jul 24, 2019

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 24, 2019 1
New Here ,
Jul 24, 2019

Copy link to clipboard

Copied

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?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 24, 2019 0
Most Valuable Participant ,
Jul 24, 2019

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 24, 2019 0
New Here ,
Jul 24, 2019

Copy link to clipboard

Copied

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?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 24, 2019 0
Adobe Community Professional ,
Jul 24, 2019

Copy link to clipboard

Copied

Use something like this:

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 24, 2019 0
New Here ,
Jul 24, 2019

Copy link to clipboard

Copied

Amazing guys! Thank you both very much!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 24, 2019 0
Adobe Community Professional ,
Jul 24, 2019

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 24, 2019 0