I created from that has form templates. I want to use JavaScript to control user entries but I don't know how to call the form fields because the names change.

New Here ,
Apr 02, 2018 Apr 02, 2018

Copy link to clipboard

Copied

Looking for information on how to use JavaScript with form fields create from a form template. I don't know how to get the form field names as they change when they are create from a template.

Thanks

TOPICS
Acrobat SDK and JavaScript

Views

135

Likes

translate

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
community guidelines

correct answers 1 Correct Answer

Most Valuable Participant , Apr 02, 2018 Apr 02, 2018
The simplest way to do it is to apply the following custom calculation script to this field:if (event.target.name!="P3.CA PG 1 TEMP.recipient") event.value = this.getField("P3.CA PG 1 TEMP.recipient").valueAsString;

Likes

translate

Translate

Translate
Most Valuable Participant ,
Apr 02, 2018 Apr 02, 2018

Copy link to clipboard

Copied

The names of spawned form fields are predictable. They contain the template name, the new page number and the original field name.

Likes

translate

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
community guidelines
New Here ,
Apr 02, 2018 Apr 02, 2018

Copy link to clipboard

Copied

I have multiple template pages within this form. I have added buttons that allow the user to put different pages in different locations in the form. Example: This field "P3.CA PG 1 TEMP.recipient" can appear on multiple pages. I want to use JavaScript to transfer the value entered on page one to the other field(s) create on all other template pages.  

Likes

translate

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
community guidelines
Most Valuable Participant ,
Apr 02, 2018 Apr 02, 2018

Copy link to clipboard

Copied

The simplest way to do it is to apply the following custom calculation script to this field:

if (event.target.name!="P3.CA PG 1 TEMP.recipient") event.value = this.getField("P3.CA PG 1 TEMP.recipient").valueAsString;

Likes

translate

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
community guidelines
New Here ,
Apr 02, 2018 Apr 02, 2018

Copy link to clipboard

Copied

Thanks, that helps. I have one more question. Keep in mind that this template page can appear on any page. I have a button "P3.CA PG 1 TEMP.addRCCode" that call this function  "addRCCode". The function pulls the value from this field "RCCodeMenu" and puts it in this field "RCCodeText". Is there a way to call these fields using just the last part of the fields name (Example ".RCCodeText")? I am sorry for being a Nuisance. Thanks again.

function addRCCode()
{
var r = this.getField("RCCodeMenu").value;
var s = this.getField("RCCodeText");
var stext = this.getField("RCCodeText").value;

if (stext == ""){
  s.value = (stext + r);
}
if (stext != ""){
  s.value = (stext + " , " +  r);
}

}

Likes

translate

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
community guidelines
Most Valuable Participant ,
Apr 02, 2018 Apr 02, 2018

Copy link to clipboard

Copied

The field name is just a string. You can manipulate it just like any other string. You can split it, replace parts of it, etc.

Likes

translate

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
community guidelines
New Here ,
Apr 02, 2018 Apr 02, 2018

Copy link to clipboard

Copied

Can you provide an example of how to do that?

Likes

translate

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
community guidelines
New Here ,
Apr 02, 2018 Apr 02, 2018

Copy link to clipboard

Copied

I found that that by setting the spawn command to false the template will keep there original names. Sorry to be so much trouble.

spawn(this.numPages,false,false);

Thanks again Try67.

Likes

translate

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
community guidelines