Skip to main content
Richard Thorp
Participating Frequently
August 30, 2018
Answered

Auto update textbox values from another field value not working

  • August 30, 2018
  • 1 reply
  • 8120 views

Hi All,

I'm sorry if I've not found an existing post that may resolve this issue. I've spent days researching and trying different variations but nothing seems to work. I'm new into using PDF and javascript so I'll try to be as clear and basic as I can. It's likely I'm not using "prepare forms" for it's intended use but I'm hoping there's a workaround.

I'm creating a fillable document and I need to have the details of one-page (Customer and Company Details) update the details of a few other pages within the whole document to avoid duplication and to save the time of the salesperson.

For example, on the first page we are completing "Enquiry - Company Name" (Textbox) and then on the 2nd page, the text box "Survey - Company Name" would automatically populate with the "Enquiry - Company Name" value and so on and so on through the document.

I've tried some of the following options: either through an "On Blur" Javascript option or a "Custom Keystroke Script" but nothing seems to work.

var n1 = this.getField("Enquiry - Company Name");

var n2 = this.getField("Survey - Company Name");

n2.value = n1.value;

this.getField("Survey - Company Name").value = this.getField("Enquiry - Company Name").value;

event.value = this.getField("Enquiry Pad – Business Name).value;

Any help would be greatly appreciated.

Thanks

Gary

This topic has been closed for replies.
Correct answer try67

Hi Bernd,

I'm not sure why as per the screenshot it's showing it for me. I've re-saved the file and if you try this link it will be in there now.

https://1drv.ms/b/s!AvmCmkb3rUqvsXixw_ayBWt8ndk6

As mentioned, the line of the script, I've already tried and it works in a blank document, but for some reason, something is stopping it in my document.

Thanks


Now it's there, and as soon as you edit the value of any field this error message appears:

TypeError: this.getField("Enquiry Pad \u2013 Business Name") is null

1:Field:Calculate

This means you used the wrong field name, most likely do to the non-standard hyphen in the middle.

Don't use something like Word to edit the code, only a plain-text editor, like Notepad.

1 reply

try67
Community Expert
Community Expert
August 30, 2018

Simply give both fields the same name and they'll have the same value automatically...

Richard Thorp
Participating Frequently
August 30, 2018

Hey try67,

oh my, I didn't think it would be so simple. However, it does cause another issue for me in that I wanted to protect the other fields on the other pages from being edited and as they are now "technically" the same field it's not going to allow me to do that. Is there another way around this?

Thanks again :-)

Gary

try67
Community Expert
Community Expert
August 30, 2018

Yes. Let's say you want to copy the value from Text1 to Text2. Use this code as the custom calculation script of Text2:

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