Skip to main content
Participating Frequently
April 9, 2024
Question

spawn template off dropdown list

  • April 9, 2024
  • 2 replies
  • 2753 views

How can i generate a 3 page template depending on a dropdown choice?

For example on the dropdown, choices 1 - 10 numbers

if the # 5 is chosen, then to spawn 5 set of templates.

 

Also need these to spawn in the middle of the document, so leaving a 1 page conclusion always at the end. 

This topic has been closed for replies.

2 replies

Participating Frequently
April 10, 2024

Thank you for the response Thom. I have changed this to my template name 

var oTmpl = this.getTemplate(....);

 

However, when i choose any number on the dropdown, nothing happens. Is there something else that needs to be set here? Sorry for the basic questions, im pretty new to this. 

Thom Parker
Community Expert
April 10, 2024

Ahh, my bad. The value of a list field is the value of the export value of the selected item. However, in the Validate event, event.value returns the display text, not the export. 

So there are two ways to fix this.

1) Search the list items for the matching display value to get the index, which can then be used to get the export value. 

2) Move the code to the Keystroke event, which provides the export value in the event object. 

 

Here's the code for the keystroke:

if(!event.willCommit && !isNaN(event.changeEx))
{
    var nLen = Number(event.changeEx);
    var oTmpl = this.getTemplate(....);
    var oXObj = null;
    var nTgtPg;
    for(i=0;i<nLen;i++)
    {
      nTgtPg = this.numPages-2;
      if(oXObj)
          oTmpl.spawn(nTgtPg, false, false, oXObj);
      else
          oXObj = oTmpl.spawn(nTgtPg, false, false);
    }
}

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Participating Frequently
April 10, 2024

Hello Thom,

 

Thank you for your help, but I cannot seem to be able to set this up the correct way,  I am attaching a copy of the document i am working on. Could you please take a look? Much appreciated!

Thom Parker
Community Expert
April 9, 2024

Add this code to the validate script for the dropdown

 

if(!isNaN(event.value))
{
    var nLen = Number(event.value);
    var oTmpl = this.getTemplate(....);
    var oXObj = null;
    var nTgtPg;
    for(i=0;i<nLen;i++)
    {
      nTgtPg = this.numPages-2;
      if(oXObj)
          oTmpl.spawn(nTgtPg, false, false, oXObj);
      else
          oXObj = oTmpl.spawn(nTgtPg, false, false);
    }
}
Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often