Skip to main content
Known Participant
August 14, 2023
Question

Attach a file Button that shows the preview/file on the button(Box) they clicked on

  • August 14, 2023
  • 1 reply
  • 3266 views

Okay, here is my situation.  I want to create a button that is interactive, but in a simple way.  Thanks to other forums, here's what I have done so far.  Go to Forms, Add button, size it and Save.  Then go to properties/Actions/Run A Javascript/Add and put input: if (app.viewerVersion < 11) etc.... OK then I go to Tools, Javascript/Document Javascript and put in my script.  Thanks to all in previous chats.  All of that works well.  The only one thing, I need now that will make it perfect, is to be able to preview the pdf/jpeg that I attachment as a small image as well as an attachment.  Now I did however find a way to do it using this: ( event.target.buttonImportFile();) but the only problem is that particular script attached to the button, causes the browse file search, to open twice to do 1 file.  Once to lock in the icon, then a 2nd time to attach the file.  So is there anyway to insert a script, in the open javascript button that will save the mini-image on the button  and save the attachment together as one?  Any help would be GREATLY appreciated.  See illustration for further details.

This topic has been closed for replies.

1 reply

try67
Community Expert
Community Expert
August 15, 2023

It should only take one selection. What exact code did you use?

And no, JS can't be used to display a preview thumbnail of the selected image. That's up to the application and/or the OS's file selection dialog.

Known Participant
August 15, 2023

Hi Try 67, I must have found something, new.   As you see in the pic, my button does have a thumbnail .  As stated above I use 2 javascript entries.  The first one is clicking on the button, and under javascript I input the 1st script and the 2nd java entry is under the Document Javascripts Toolbox.  See Attached forms for a more detailed explanation.  Thanks.

Bernd Alheit
Community Expert
Community Expert
August 16, 2023

I assuming you are referring to the 1st Javascript line, under Run a javascript?
which is: event.target.buttonImportIcon();
I did just keep this.  It loads the thumbnail but does not load the file.  That defeats the purpose. When I view attachments, nothing has uploaded.   Unless I am missing something, that don't work.  Any other ideas? 


To add attachments use the functions import_pre_11() or import_11()