Skip to main content
Inspiring
June 7, 2024
Answered

How to add pages based on a dropdown value ?

  • June 7, 2024
  • 2 replies
  • 1514 views

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 ?

This topic has been closed for replies.
Correct answer PDF Automation Station

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();}

2 replies

Nesa Nurani
Community Expert
Community Expert
June 7, 2024

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.

 

PDF Automation Station
Community Expert
Community Expert
June 7, 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();}

Inspiring
June 7, 2024

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

Inspiring
June 7, 2024

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

this.pageNum=1}