Copy link to clipboard
Copied
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;}
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);}
Copy link to clipboard
Copied
Also, this bad parameter error prevents me from saving this document.
Copy link to clipboard
Copied
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:
Copy link to clipboard
Copied
Yes sir. Page 1 template is "1" and page 2 template is "2"
Copy link to clipboard
Copied
Also, there are only two pages in this document. I mean it works but I keep getting a bad parameter error and it messes up the document where I can't save it and it starts acting all weird.
Copy link to clipboard
Copied
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);}
Copy link to clipboard
Copied
A PDF cannot have 0 pages. Both pages cannot be hidden templates
About your script. Where is "nTargetPageNumber" set?
Did you check the console window for errors?
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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);}
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Something I just noticed,
My original code works so long as page 1 is the only page in the window. If I scroll down midway to where the bottom of page 1 and the top of page 2 are in the window, then I get the bad parameter error. Actually, if any part of page 2 is visible, then I get the bad parameter error. The code still works regardless. But what is weird, is that nothing comes up in the debugger.
Any ideas?
if(event.target.value!="Off")
{this.getTemplate("2" ).hidden=false;}
else
{this.getTemplate("2" ).hidden=true;}
Copy link to clipboard
Copied
The bad parameter is at page 2.
Copy link to clipboard
Copied
Why is there a bad parameter when the code works and there are no errors?
Copy link to clipboard
Copied
There is no connection between the error and the script.
Copy link to clipboard
Copied
So what do I do?
Copy link to clipboard
Copied
Re-create page 2.
Copy link to clipboard
Copied
The spawn code is correct, so the error is somewhere else. Forget about the original show/hide code, it can't be used for a distributed document.
You state that when you click the checkbox, page 2 is deleted. So your saying the template page is visible before you click the checkbox? If so, then you are deleteing the template. So of course nothing happens when you uncheck, because the template doesn't exist at that point.
Template pages need to be hidden before they are put into operation.
Copy link to clipboard
Copied
Yes sir. Page 1 and 2 templates are visible when the checkbox is clicked. When I uncheck the checkbox, page 2 is deleted.
So do I need to have two copies of page 2 template and hide one of them so then it will continually spawn off the hidden copy? Or something else?
By the way, I also get the bad parameter error as well.
Copy link to clipboard
Copied
I figured it out. It is working now. The "sequence" was off I think. I removed (cut) the code, unchecked the box, pasted it back in, hid page 2 template, then checked the box and it works.
But still I get a bad parameter error if I scroll down midway to where the bottom of page 1 and the top of page 2 are in the window or if any part of page 2 is visible. I still get the bad parameter error. Still nothing comes up in the debugger.
Copy link to clipboard
Copied
Perhaps a workaround would be to jump up to page 1 before deleting the 2nd page (since everything works without error so long as none of page 2 is in the window? I don't know how to do that though.
Copy link to clipboard
Copied
If page #1 is never spawned or deleted then there is no reason for it to be a page template. In fact, making it a template is problematic. Remove it from the page template so it is a normal page.
Since page #2 is spawned and deleted, it does need to be setup a as a page template. But it needs to be set to hidden. The checkbox and script will need to be synchronized with the template, so there is no confusion. The simplest way to do this is to check the number of pages in the document. If there are two pages, then obviously the template has already been spawned, and if there is only one page then the template page has already been deleted. Here's a modification of the script.
if((event.target.value!="Off") && (this.numPages == 1))
this.getTemplate("2" ).spawn(1, false, false);
else if(this.numPages > 1)
this.deletePages(1);
The error message that pops up is likely caused by some type of inernal structural problem on the page. Bernd is correct. You need to recreate this page. In fact, I'd suggest starting over and recreate the entire document.
Copy link to clipboard
Copied
Ok. I will recreate the entire document and let you know.
Copy link to clipboard
Copied
I recreated the entire document and it still gave me bad parameter error....very strange
Copy link to clipboard
Copied
What is your process for creating the document?
Can you post the PDF?
Copy link to clipboard
Copied
Yes sir. See attached.
I found a workaround though. I added a custom zoom level action at the beginning before running all the java actions. For whatever reason, the bad parameter error never occurs so long as page 1 is the only page visible in the window. If any part of page 2 is visible, the error displays (even though the code runs successfully). This way anytime I check or uncheck the box, the first thing it does is jump to page 1 before hiding/ unhiding page 2 (in addition to the other actions).
As for the process, I just started from the top of page 1 and worked my way down the page onto page 2 adding all of the fields, etc.