Copy link to clipboard
Copied
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})
}
Use deletePages
The "deletePages" function is a member of the document object.
So it's this.deletePages(...)
Always check the Acrobat JavaScript Reference.
Copy link to clipboard
Copied
Use deletePages
Copy link to clipboard
Copied
Hello! Thank you for the advice but it still doesn't work. Any other recommendations?
Copy link to clipboard
Copied
Check the JavaScript console for errors.
Copy link to clipboard
Copied
I used the javascript console and it gave me the following error:
"SyntaxError: syntax error
1:Console:Exec
undefined"
Any advice?
Copy link to clipboard
Copied
Sorry I error was
TypeError: event.target is undefined
5:Console:Exec
undefined
Copy link to clipboard
Copied
Where does you use the script?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Did you not read my post? That advice still didn't work and I figured it out myself.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
I don't know what is your problem. Bottom line, pdf script is working now. Thank you.
Copy link to clipboard
Copied
deletepages will not work. Use this.deletePages.
Copy link to clipboard
Copied
Sorry that's what I meant. I used "this.deletePages" and deleted the "c.".
Copy link to clipboard
Copied
The "deletePages" function is a member of the document object.
So it's this.deletePages(...)
Always check the Acrobat JavaScript Reference.
Copy link to clipboard
Copied
Hello, thank you for the advice but it still didn't work.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now