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

Java Script Delete Page

New Here ,
Oct 19, 2023 Oct 19, 2023

Hello I'm new to javascript.  I'm pretty much googling everything so if I do not use the correct nomenclature, my apologies.  I have a pdf document with a check box.  I would like this check box to spawn a "medical" form and make two fields hidden and when they uncheck the box, I would like for the "medical" form to be deleted and the two fields to be visible.  So far, I have been able to write a javascript where it does everything except for deleting the "medical" page.  No matter how I try to write the script, I can't get it to delete the "medical" form. Below is my script.  Can anyone help?

var a = this.getField("Please Answer");
var b = this.getField("Questions");
var c = this.getTemplate("Medical")

if(event.target.value == "Yes"){
a.display = display.hidden;
b.display = display.hidden;
c.spawn(event.target.page+5, false, false)
}

else if(event.target.value == "Off"){
a.display = display.visible;
b.display = display.visible;
c.deletePage({nStart: 6})
}

TOPICS
Acrobat SDK and JavaScript , Windows
1.8K
Translate
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

correct answers 2 Correct answers

Community Expert , Oct 19, 2023 Oct 19, 2023

Use deletePages

Translate
Community Expert , Oct 23, 2023 Oct 23, 2023

The "deletePages" function is a member of the document object.

So it's this.deletePages(...)

 

Always check the Acrobat JavaScript Reference.

 

 

Translate
Community Expert ,
Oct 19, 2023 Oct 19, 2023

Use deletePages

Translate
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
New Here ,
Oct 20, 2023 Oct 20, 2023

Hello!  Thank you for the advice but it still doesn't work.  Any other recommendations?

Translate
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 ,
Oct 20, 2023 Oct 20, 2023

Check the JavaScript console for errors.

Translate
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
New Here ,
Oct 24, 2023 Oct 24, 2023

I used the javascript console and it gave me the following error:

 

"SyntaxError: syntax error
1:Console:Exec
undefined"

 

Any advice?

Translate
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
New Here ,
Oct 24, 2023 Oct 24, 2023

Sorry I error was 

TypeError: event.target is undefined
5:Console:Exec
undefined

Translate
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 ,
Oct 24, 2023 Oct 24, 2023

Where does you use the script?

Translate
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 ,
Oct 24, 2023 Oct 24, 2023

The "event" object is not defined in the console window.  If you want to test a field script in the console, then you'll need to replace "event.target" with the correct field object

 

But there is no reason to do this. Make the changes to the MouseUp script and then look in the console before and after clicking on the checkbox to see if any errors are reported. 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
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
New Here ,
Oct 24, 2023 Oct 24, 2023

Hello everyone! I incorporated everyone's advice and what really made the script work was I just deleted the "c." In front of the "deletepages" and it worked. Thank you!

Translate
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 ,
Oct 25, 2023 Oct 25, 2023

Did you not read my post?  The correct form is "this.deletePages()", because that function is a member of the document object, not the field object.  

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
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
New Here ,
Oct 26, 2023 Oct 26, 2023

Did you not read my post? That advice still didn't work and I figured it out myself. 

Translate
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 ,
Oct 26, 2023 Oct 26, 2023

If that's true, then why did you just write that "c." was still in front of the "deletePages" ?  Obviously you didn't follow the advice. 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
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
New Here ,
Oct 26, 2023 Oct 26, 2023
LATEST

I don't know what is your problem.  Bottom line, pdf script is working now.  Thank you.

Translate
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 ,
Oct 26, 2023 Oct 26, 2023

deletepages will not work. Use this.deletePages.

Translate
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
New Here ,
Oct 26, 2023 Oct 26, 2023

Sorry that's what I meant.  I used "this.deletePages" and deleted the "c.".

Translate
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 ,
Oct 23, 2023 Oct 23, 2023

The "deletePages" function is a member of the document object.

So it's this.deletePages(...)

 

Always check the Acrobat JavaScript Reference.

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
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
New Here ,
Oct 24, 2023 Oct 24, 2023

Hello, thank you for the advice but it still didn't work.

Translate
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