Skip to main content
Known Participant
July 10, 2023
Answered

Delete spawned page depending on dropdown choice

  • July 10, 2023
  • 1 reply
  • 877 views

I have a 2 page document that contains 2 hidden templates.

I have a 'Title' dropdown field at the top of page 1 which has 3 options. Options 1 and 3 will each spawn an additional page at the end of the document.

This works perfectly.

The issue comes if someone decided to change the 'Title'. For instance, if they had originally picked Option 1, the corresponding page will spawn for this. If they then change to Option 3, the page for this will spawn.

What I would like to happen is have the spawned page disappear if a different option in the Title field is chosen.

Is this possible?

 

This is the code that is in the Title drop down to spawn the pages:

if(event.value == "Abonnement Service Intégral")
this.getTemplate("Option1").spawn(this.numPages, false, false);
else if(event.value == "Abonnement Connect – RH")
this.getTemplate("Option3").spawn(this.numPages, false, false);

 

This topic has been closed for replies.
Correct answer Bernd Alheit

When there are more then 2 pages delete the last page.

1 reply

Bernd Alheit
Community Expert
Bernd AlheitCommunity ExpertCorrect answer
Community Expert
July 10, 2023

When there are more then 2 pages delete the last page.

jlehaneAuthor
Known Participant
July 10, 2023

What would I add to the above script to make that happen?

 

Thom Parker
Community Expert
Community Expert
July 10, 2023

No mater what is selected, the last page needs to be deleted if it was spawned. So add delete code to the top of the script

if(this.numPages >2) this.deletePages(2);

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often