Skip to main content
Inspiring
October 6, 2023
Answered

Button to show/ hide page templates

  • October 6, 2023
  • 2 replies
  • 8666 views

I have a check box button on page 1.  The following code works to show/hide page 2 .  Click the button, show page 2.  Unclick the button, hide page 2.

 

However, it gives me a "bad parameter" despite working.  Any ideas?

 

if(event.target.value!="Off")
{this.getTemplate("2" ).hidden=false;}
else
{this.getTemplate("2" ).hidden=true;}

This topic has been closed for replies.
Correct answer Thom Parker

It has two pages.  First page is always visible.  2nd page is what the button will show/hide.  Button is on page 1.

How do I set target page number?

 


Ok the target page isn't set. That is the source of the error.   Page numbers in the Acrobat JavaScript model are zero based. Page #1 is 0, and Page #2 is 1;

 

Use this code:

if(event.target.value!="Off")
{this.getTemplate("2" ).spawn(1, false, false);}
else
{this.deletePages(1);}

 

 

2 replies

Thom Parker
Community Expert
October 6, 2023

Is the Template named "2"?  If not I don't see how the code could work. Also, unhiding a template always places the page at the end of the document. You can't specify the page where it will appear. 

 

Also, hiding and showing a template will not work in Reader. The correct way to use a template is to "spawn" it. 

This thread provides a checkbox spawn solution:

https://community.adobe.com/t5/acrobat-discussions/spawn-templates-after-a-specific-page-with-checkboxes/m-p/14137819#M432760

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
MBChelsAuthor
Inspiring
October 6, 2023

I tried the code from the thread you provided and nothing happened

if(event.target.value!="Off")
{this.getTemplate("2" ).spawn(nTargetPageNumber, false, false);}
else
{this.deletePages(nTargetPageNumber);}

 

MBChelsAuthor
Inspiring
October 10, 2023

Ok the target page isn't set. That is the source of the error.   Page numbers in the Acrobat JavaScript model are zero based. Page #1 is 0, and Page #2 is 1;

 

Use this code:

if(event.target.value!="Off")
{this.getTemplate("2" ).spawn(1, false, false);}
else
{this.deletePages(1);}

 

 


Hi Sir,

 

When I click the checkbox, page 2 is deleted.  When I unclick it, nothing happens.  There is no way to bring back page 2.  So this code doesn't appear to work still.

MBChelsAuthor
Inspiring
October 6, 2023

Also, this bad parameter error prevents me from saving this document.