Skip to main content
Inspiring
May 10, 2022
Answered

Template Pages - Prefixes and javascripts with checkboxes

  • May 10, 2022
  • 3 replies
  • 717 views

My form has a 14 checkboxes that turns the visibility on/off of two corresponding fields each. One field is an image field, the second field is a test field. The reason is if someone doesn't have an image then the text is to display.

 

The scipt i have on the checkbox is working well:

//checkbox on/off toggle visibility
if (event.target.isBoxChecked(0)){
this.getField("Image1_af_image").display = display.hidden;
this.getField("AskDetails1").display = display.visible;
} else {
this.getField("Image1_af_image").display = display.visible;
this.getField("AskDetails1").display = display.hidden;
}

 

The form also has an "add page" button with a template page applied to it. The template page is identical to the first page with the exeption that all the additional fields have numbering continuing on from 15 to 28. (example "AskDetails15" and "Image15_af_image")

 

Each checkbox again has the same javascript to toggle visibility on/off:

//checkbox on/off toggle visibility
if (event.target.isBoxChecked(0)){
this.getField("Image15_af_image").display = display.hidden;
this.getField("AskDetails15").display = display.visible;
} else {
this.getField("Image15_af_image").display = display.visible;
this.getField("AskDetails15").display = display.hidden;
}

 

Which of course functions on the template page itself but not on the generated pages which now each field has the prefix (example) P2.Template.AskDetails15.

 

How do I write the script to include the variable prefix number?

This topic has been closed for replies.
Correct answer default6i0u6ss6wf59

I created the following after finding cath.g's answer here: https://community.adobe.com/t5/acrobat-discussions/check-all-checkbox-not-working-on-spawned-pages/m-p/11260164#M264570

 

Thank you cath.g!

 

var cPreFix = "";
// get prefix elements for spawned pages;
var aFieldName = event.target.name.split(".");
if(aFieldName.length > 2)
{
// first 2 elements of name array makeup the prefix for fields on a spawned page;
cPreFix = aFieldName[0] + "." + aFieldName[1] + ".";
}
// ifelse conditional statement checkbox on/off toggle visibility
if (event.target.isBoxChecked(0)){
this.getField(cPreFix +"Image15_af_image").display = display.hidden;
this.getField(cPreFix +"AskDetails15").display = display.visible;
} else {
this.getField(cPreFix +"Image15_af_image").display = display.visible;
this.getField(cPreFix +"AskDetails15").display = display.hidden;
}

This applied to each checkbox with the corresponding "AskDetails" and "Image#" names now works perfectly.

3 replies

default6i0u6ss6wf59AuthorCorrect answer
Inspiring
May 12, 2022

I created the following after finding cath.g's answer here: https://community.adobe.com/t5/acrobat-discussions/check-all-checkbox-not-working-on-spawned-pages/m-p/11260164#M264570

 

Thank you cath.g!

 

var cPreFix = "";
// get prefix elements for spawned pages;
var aFieldName = event.target.name.split(".");
if(aFieldName.length > 2)
{
// first 2 elements of name array makeup the prefix for fields on a spawned page;
cPreFix = aFieldName[0] + "." + aFieldName[1] + ".";
}
// ifelse conditional statement checkbox on/off toggle visibility
if (event.target.isBoxChecked(0)){
this.getField(cPreFix +"Image15_af_image").display = display.hidden;
this.getField(cPreFix +"AskDetails15").display = display.visible;
} else {
this.getField(cPreFix +"Image15_af_image").display = display.visible;
this.getField(cPreFix +"AskDetails15").display = display.hidden;
}

This applied to each checkbox with the corresponding "AskDetails" and "Image#" names now works perfectly.

try67
Community Expert
Community Expert
May 11, 2022

What's the name of the check-box that triggers this event?

Inspiring
May 11, 2022

The checkbox name is NoQR15.

15 is the corresponding number to the effected fields.

The last checkbox is NoQR28. 

Bernd Alheit
Community Expert
Community Expert
May 11, 2022

You can extract the prefix from event.target.name