Delete button script to delete two consecutive pages in the middle of a document.
Copy link to clipboard
Copied
Hi. I've been roped into creating a credit card application and have zero javascript experience. I've been doing the best I can but have ran into something I cannot seem to work around.
When selecting the appropriate legal structure (using radial boxes with four options), we need to spawn a two page resolution. The spawning works just fine. However, if a person selects "Corporation" and then selects "Partnership," both resolutions are spawned. If I could code, I would have written the script to delete the spawned pages when selecting a different radial button (I did try and got it to work by hiding/unhiding the templates...doesn't work on all versions). So....I added a delete page button on each resolution but can't figure out how to make it work if the two pages to delete happen to be in the middle of the document. This works fine if no other pages are spawned throughout the document but, as you can see, this deletes all but 4 of the pages (that's the starting point of the application). Any advice on either fixing the code for the delete button or fixing the code for the spawn would be greatly appreciated.
For the Delete button I'm using the following:
if (numPages > 5) {
this.deletePages(4, this.numPages-1);
}
For spawning the resolutions, I'm using the following:
var a=this.getTemplate("LLC Auth")
var b=this.getTemplate("LLC Auth2")
if(event.target.value == "Off")
this.deletePages(event.target.page+1);
else
a.spawn(numPages,false,false);
b.spawn(numPages,false,false);
this.pageNum=event.target.page+1;
this.pageNum=-1;
Copy link to clipboard
Copied
If you don't want to have more than two spawned pages at a time then in the same 'radio' button where you spawn pages, first add script to delete pages if the number of pages is bigger than 4 and then script to spawn pages.
Copy link to clipboard
Copied
That's what I currently have setup. Unfortunately, there are times when the user can spawn additional pages (for a different reason) resulting in more than 4 pages, ultimately deleting any work they may have completed prior to.

