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

How to add pages based on a dropdown value ?

Explorer ,
Jun 07, 2024 Jun 07, 2024

Copy link to clipboard

Copied

I have two template pages that I would like to appear if one of the three options are selected in a dropdown menu on a first permanent page. If option A is selected, I would like the first template page to appear. If B or C is selected, I would like the second template page to appear. What is the javascript code for this ?

TOPICS
How to , JavaScript

Views

115

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

Engaged , Jun 07, 2024 Jun 07, 2024

Assuming the dropdown values are A, B, and C, select "Commit selected value immediately" in the options tab of the dropdown then enter the following custom validation script:

if(event.value=="A")

{this.getTemplate("Template 1").spawn();}

if (event.value == "B" || event.value=="C")

{this.getTemplate("Template 2").spawn();}

Votes

Translate

Translate
Engaged ,
Jun 07, 2024 Jun 07, 2024

Copy link to clipboard

Copied

Assuming the dropdown values are A, B, and C, select "Commit selected value immediately" in the options tab of the dropdown then enter the following custom validation script:

if(event.value=="A")

{this.getTemplate("Template 1").spawn();}

if (event.value == "B" || event.value=="C")

{this.getTemplate("Template 2").spawn();}

Votes

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
Explorer ,
Jun 07, 2024 Jun 07, 2024

Copy link to clipboard

Copied

But, let's say I don't want to make it show at the end of the document, but after the third page ?

Votes

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
Explorer ,
Jun 07, 2024 Jun 07, 2024

Copy link to clipboard

Copied

I got the answer spawn(3, false, false);

this.pageNum=1}

Votes

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
Engaged ,
Jun 07, 2024 Jun 07, 2024

Copy link to clipboard

Copied

The first "false" is whether you want the fields renamed or not.  If you only want the pages spawned once per selection of the dropdown, I would suggested using check boxes instead that spawn the page if it's checked and remove it if it's unchecked.  This article outlines in detail how to do it, with practice files you can download, and video:

https://pdfautomationstation.substack.com/p/check-boxes-that-show-and-hide-pdf

 

 

Votes

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
Engaged ,
Jun 07, 2024 Jun 07, 2024

Copy link to clipboard

Copied

if(event.value=="A")

{this.getTemplate("Template 1").spawn(3, true, false);}

if (event.value == "B" || event.value=="C")

{this.getTemplate("Template 2").spawn(3, true, false);}

 

Votes

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
Community Expert ,
Jun 07, 2024 Jun 07, 2024

Copy link to clipboard

Copied

Just keep in mind that with this code if the user changes their mind after selecting A and switched to B, the first page that was spawned will still be there, alongside the second page... To prevent that from happening you should check the number of pages in the file when a selection is made, and delete any spawned pages, if they exist.

Votes

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
Explorer ,
Jun 10, 2024 Jun 10, 2024

Copy link to clipboard

Copied

Do you know why template 1 always appeared after the template that appeared accordingly to the choice in the drop down menu ?

Votes

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
Explorer ,
Jun 10, 2024 Jun 10, 2024

Copy link to clipboard

Copied

LATEST

Forget about it, I got the answer. I needed to put the different templates in the same {}

Votes

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
Community Expert ,
Jun 07, 2024 Jun 07, 2024

Copy link to clipboard

Copied

Something like this:

 

var t1 = this.getTemplate("Template1");
var t2 = this.getTemplate("Template2");
if (event.value == "A")
t1.spawn(this.numPages, false, false);
else if(event.value == "B" || event.value == "C")
t2.spawn(this.numPages, false, false);

You could also add to the script to delete a page, if for example you select A and then change your mind and select B or C.

 

Votes

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