JavaScript for a "Clear" Button for the attached files in a pdf-form
Hello Guys,
I need help with my 2 buttons I have created in a PDF-form so that the person filling the for can Attach a file from his Browser and the file name will be visible in another field. However I need one more button so that it "Clears" the attached files.
This is my JavaScript that works for attaching a file and so that the file name is shown:
try {
var annot = this.addAnnot({
page: 0,
type: "FileAttachment",
point: [500, 500],
noView: true,
author: "Attachment"
});
annot.cAttachmentPath;
var attachmentObj = annot.attachment;
if (attachmentObj !== null) {
app.alert("Add this file: " + attachmentObj.name);
var l = this.getField("lst1");
if (l.value == "") {
l.value = attachmentObj.name;
}
else {
l.value = l.value + "\n" + attachmentObj.name;
}
}
}
catch(e) {
if (e.name == "NotAllowedError") {
// do nothing
}
}
--------------------------------------------------
Now I need another button so that if the person want to take the attached file off he can do it with a button click.
And my JavaScript, that does not work for that is:
this.syncAnnotScan () ;
var annots = thisgetAnnots({
nPage: 0,
nSortBy: ANSB_Type
});
for (var i=0; i<annots.length; i++) {
if (annots .type =="FileAttachment") {
annots.destroy();
}
}
var 1 = this.getField ("lst1") ;
l.ClearItems();
---------------------------------------------------------
When I run this JavaScript in the form I get the: SyntaxError: missing variable name
12: at line 13 Ln13, Col16
----------------------------------------------------------------------------------------------------------------
Can someone please help me make this "Clear" button I need to work.
What have I done wrong?
I got my info from this video on youtube:
How to attach a file to PDF form with Adobe Acrobat - YouTube
I would appriciate it SOOOOO MUCH!!!!
Kind Regards
Stefan.S from Sweden
