I am facing a problem in Adobe form; I have 2 buttons BROWSE1 and BROWSE2 on Adobe Form and two Text fields TEXT1 and TEXT2, on clicking of either of the buttons a popup appears on the asking the User to select the file that has to be uploaded. After I have selected the File in TEXT1 after clicking BROWSE1, I can see the file name in TEXT1.
When I click on the BROWSE2 the popup appears asking the user the to select the file to be uploaded, however if I cancel the popup at this point, ideally I shouldn’t see any file name in TEXT2, but the last file name which was uploaded through BROWSE1 in TEXT1 is getting copied in TEXT2. Whenever the cancel button on either of the BROWSE buttons is clicked the Last file which was selected gets populated in the either of the TEXT fields. I have tried number of things using the JAVA script but this doesn’t seem to be working properly. Since I am not a JAVA programmer please let me know if there is possible solution to above explained problem, I am providing the code below which I have used for your convenience.
BROWSE1:
var sFile = null;
event.target.importDataObject(sFile);
var oFile = null;
oFile = event.target.getDataObject(sFile);
this.parent.parent.Sub_4.FILE_PATH_PID.rawValue = oFile.path;
var pFile = event.target.getDataObjectContents(sFile);
var cFile = util.stringFromStream(pFile, "utf-8");
ADOBE_DATA.Main_Subform.Main_Form.Sub_4.FILE_CONTENT_1 = cFile;
BROWSE2:
var xFile = null;
event.target.importDataObject(xFile);
var gFile = null;
gFile = event.target.getDataObject(xFile);
this.parent.parent.Sub_4.FILE_PATH_WBS.rawValue = gFile.path;
var aFile = event.target.getDataObjectContents(xFile);
var mFile = util.stringFromStream(aFile, "utf-8");
ADOBE_DATA.Main_Subform.Main_Form.Sub_4.FILE_CONTENT_2.rawValue = mFile;
First, the "importDataObject()" function returns false if the user hits "Cancel". The code should switch off of this return value. The fact that it doesn't means that an exception is going to be caused down the line, if there are no other imported files. The code needs to test the return.
Next, you are naming the imported file "null" on both buttons. So, the JS code can't distinguish between files that were imported by the different buttons. So if you import a file with button 1, then cancel the button 2 import, the code grabs the data from the first import, because they have the same name.
Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]
The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/]http://www.adobe.com/devnet/acrobat/[/url]
Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script