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 ?
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();}
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();}
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 ?
Copy link to clipboard
Copied
I got the answer spawn(3, false, false);
this.pageNum=1}
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
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);}
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.
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 ?
Copy link to clipboard
Copied
Forget about it, I got the answer. I needed to put the different templates in the same {}
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.