• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
13

Javascript to delete pdf pages using a form field as page marker

Explorer ,
Feb 13, 2024 Feb 13, 2024

Copy link to clipboard

Copied

Hi there,

 

I would like to know if anyone has found javascript that would find a specific form text field name and then delete the page it is on?

 

I am working on a form that new pages will be added if the client uses a dropdown to select number of accounts and the template spawns from that. But I would like to give the client the opportunity to change the number of spawn pages if they have got it wrong. Complete novice to this. I did the original with show hide javascript but the client has asked for the pages to delete. 

TOPICS
JavaScript , PDF , PDF forms

Views

1.2K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
1 ACCEPTED SOLUTION
Community Expert ,
Feb 13, 2024 Feb 13, 2024

Copy link to clipboard

Copied

You can use 'page' property to find page number of a specific field, for example let's say you want to delete page where "Text1" field is located:
var f = this.getField("Text1").page;
this.deletePages(f);

View solution in original post

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 13, 2024 Feb 13, 2024

Copy link to clipboard

Copied

You can use 'page' property to find page number of a specific field, for example let's say you want to delete page where "Text1" field is located:
var f = this.getField("Text1").page;
this.deletePages(f);

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 13, 2024 Feb 13, 2024

Copy link to clipboard

Copied

Just be aware this will only work if there's only one copy of the field. If there are more copies of it, even on the same page, the page property will return an array, not a number!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 13, 2024 Feb 13, 2024

Copy link to clipboard

Copied

PS. Also, you need to check if the page number is not -1, or you could accidentally delete the Template page (or it will produce an error).

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 14, 2024 Feb 14, 2024

Copy link to clipboard

Copied

Hi Nesa,

 

Thanks for your help. I have added the code to a Combo Box in the calculate script custom calculation area.

 

var v = this.getField("Combo Box 1").value; if (v === “two”) { var f = this.getField("Text 2").page; this.deletePages(f); } if (v=== "three"){ var g = this.getField("Text 3").page; this.deletePages(g); }

But it doesn't seem to be working.

Have I done something wrong

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 14, 2024 Feb 14, 2024

Copy link to clipboard

Copied

There are errors in your code. Check the JS Console. You must always use straight quotes, not curly ones.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 14, 2024 Feb 14, 2024

Copy link to clipboard

Copied

Many thanks, now working

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 27, 2024 Feb 27, 2024

Copy link to clipboard

Copied

Are you able to share how you got this working? I'm working on a similar issue and keep getting errors.

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 28, 2024 Feb 28, 2024

Copy link to clipboard

Copied

LATEST

It started working after I changed the typographers qupotes to regular quotes.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines