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

Conditional Form Fields on Spawned Template Pages

New Here ,
Jun 01, 2021 Jun 01, 2021

Hi experts,

First I'd like to preface by saying that I have very limited Javascript knowledge and everything I've done is based on Internet search results for use cases similar to my own.

 

I have an Adobe PDF form that consists of 2 pages with a button on the second page to spawn an additional page based on a hidden template. 

 

The intended use of this document is as a sample submission form, wherein Page 1 of the form is only completed once. Depending on the number of samples that is being submitted, Page 2 (and the template, which is the same form but a hidden page) will be duplicated between 2-20 times to be populated with information pertaining to each sample (one page per sample).

 

There are a few radio button fields on the spawned template that I would like to set conditions on. 

 

Field A, radio button options A1 and A2:

> if A1 is selected, Field B should have radio button option B1 permanently selected, Field C should be selectable from 3 radio button options;

> if A2 is selected, Field B should have two radio button options (B1 or B2) selectable, Field C should be entirely unselectable

 

I currently have the following Javascript in radio buttons A1 and A2 on Mouse Up, on the hidden template page:

A1:

if (event.target.value=="A1")
this.getField("FieldB").value = "B1";
this.getField("FieldB").readonly = true;
this.getField("FieldC").readonly = false;

 

A2:

if (event.target.value=="A2") {
this.getField("FieldB").readonly = false;
this.getField("FieldC").readonly = true;}
else {this.getField("FieldC").readonly = false;}

 

When the template is spawned via button click, all the form fields are renamed to include Pg#.TemplateName. in front of the form field names on the page. I think it's because of this that the above code doesn't work, but I'm not entirely sure. 

 

Can anyone help with rewriting the code above so that the conditions work on each page that is spawned from the template? How can this be dynamically updated based on the number of total pages in the file?

 

Thank you in advance for your help 🙂

TOPICS
JavaScript , PDF forms
1.1K
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
1 ACCEPTED SOLUTION
New Here ,
Jun 01, 2021 Jun 01, 2021

I found the solution in another forum page!

 

// Get the field name
var fieldName = event.target.name;

//strip off the last part of the name
var groupName = fieldName.substring(0,fieldName.lastIndexOf(".")+1);

 

if (event.target.value=="A1")
this.getField(groupName + "FieldB").value = "B1";
this.getField(groupName + "FieldB").readonly = true;
this.getField(groupName + "FieldC").readonly = false;

View solution in original post

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
New Here ,
Jun 01, 2021 Jun 01, 2021

I found the solution in another forum page!

 

// Get the field name
var fieldName = event.target.name;

//strip off the last part of the name
var groupName = fieldName.substring(0,fieldName.lastIndexOf(".")+1);

 

if (event.target.value=="A1")
this.getField(groupName + "FieldB").value = "B1";
this.getField(groupName + "FieldB").readonly = true;
this.getField(groupName + "FieldC").readonly = false;

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
New Here ,
Jun 06, 2021 Jun 06, 2021
LATEST
What is this
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