These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Dynamic Stamp with Dialog - Undefined variables

StampKing
Registered: Mar 18 2010
Posts: 3

Hello all,

I have exactly the same problem as this member, here's his post: http://www.acrobatusers.com/forums/aucbb/viewtopic.php?id=22488

Here is the post in it's entirety:

I have the following short script to create a custom dialog box.

var oDlg =
{
shRate:0,
initialize: function(dialog)
{
console.println("In init: this.shRate = "+this.shRate);
dialog.load({"shRateField":this.shRate});
},
commit: function(dialog)
{
var data = dialog.store();
var testString = data["shRateField"];
console.println("In commit: testString is: "+testString);
this.shRate = parseFloat(testString);
console.println("In commit: this.shRate is: "+this.shRate);
var subtotal = getField("SubtotalField").value;
var shAmount = subtotal*((parseFloat(this.shRate))/100);
console.println("Shipping & Handling Rate is: "+this.shRate+" Shipping & Handling Amount is: "+shAmount);
},
description:
{
name: "Shipping & Handling Calculation Dialog",
elements:
[
{
type:"view",
elements:
[
{
name:"Enter Shipping & Handling Rate(%):",
type:"static_text",
},
{
item_id:"shRateField",
type:"edit_text",
char_width:10
},
{
type:"ok_cancel",
},
]
}
]
}
};

//Dialog Activation
app.execDialog(oDlg);

I get the following result on the console:

In init: this.shRate = 0
In commit: testString is: undefined
In commit: this.shRate is: NaN
Shipping & Handling Rate is: NaN Shipping & Handling Amount is: NaN

When I open the dialog box I type a value of 10 in the textfield name "shRateField".Can someone help me understand why when I hit "OK" I'm getting "undefined" as the value in this field? I'm running a trial version of Adobe Acrobat Pro 9.

Many thanks,

VG

The member then says he got it to work but doesn't state how. Has anyone ran into this problem before? How did you fix it?

My Product Information:
Acrobat Pro 9.0, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
You've got a few problems. First "oDlg" is an object. So the keyword "this", when it's used in a function inside "oDlg" refers to "oDlg". It does not refer to the document object, so a call to getField() has no meaning. Next, element id's are exactly 4 characters long. Yours are much longer. Code in a dialog should only affect the dialog, and not touch anything in the PDF. If you want to see proper dialog code, download AcroDialogs and use it to create a test dialog.

http://www.windjack.com/products/acrodialogs.php

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/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

mmazal
Registered: Jul 20 2009
Posts: 27
Yes - it looks like the one name you use
"shRateField"
just needs to be changed to a four-letter variable in both places it's used.
I tried it and it seems to be okay.