Skip to main content
jonathanm75257324
Known Participant
August 8, 2018
Question

Checkbox JavaScript that toggles spawning of template, or deletion of page.

  • August 8, 2018
  • 1 reply
  • 3858 views

I'm using the following code as an action to spawn a hidden page template using a checkbox. The JavaScript works, but the issue is that each time I click the check box (check/uncheck) it will spawn a new page. I would like to toggle the checkbox to spawn the template (check) or delete the page (uncheck). 

Please note, this will be installed on machines that use Acrobat Reader, though the spawn functionality seems to work just fine.

I am using the following code as an action within each checkbox:

var a = this.getTemplate("TEMPLATE1");

a.spawn(1,false,false);

Thanks for the help! I am very new to coding and acrobat!

This topic has been closed for replies.

1 reply

Thom Parker
Community Expert
Community Expert
August 8, 2018

You didn't say, but I'm assuming this is a MouseUp action? If not then it needs to be.

The solution is to qualify the code with the state of the checkbox.

if(event.target.value == "Off")

   this.deletePage(2);

else

{

    var a = this.getTemplate("TEMPLATE1");

    a.spawn(1,false,false);

}

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
jonathanm75257324
Known Participant
August 8, 2018

Hi Thom,

Thanks for the help. Yes I am running the JavaScript on a mouseUp action.

I tried your code, and unfortunately , it does not work.

It will spawn the new page upon click.

Upon uncheck, it does nothing.

Bernd Alheit
Community Expert
Community Expert
August 8, 2018

Look at the console for errors.

deletePage is wrong you must use deletePages.