Dialog box user input checkbox to drive Dynamic Stamp checkbox

Hello to all, I have no JS knowledge whatsoever. Have been reading countless tutorials, guides and posts and have managed to create a "Dynamic Stamp" which prompts the user for certain information before it gets placed.

I just need help in passing the status/value of a checkbox within the javascript dialog box to the actual checkbox on the stamp. Any sort of help/comments would be greatly appreciated.

This is what my code looks like so far, sorry if its messy but this is what has resulted from scavenging the net:

var dialog = {
starValue: "",
mjValue: "",
accValue: "",
bChk1:false,
 bChk2:false,

initialize: function(dialog)
{
var dlgInit =
{
"Chk1": this.bChk1,
"Chk2": this.bChk2,

};
dialog.load(dlgInit);
},

commit:function (dialog) { // called when OK pressed

var results = dialog.store();
this.starValue = results["txt1"];
this.mjValue = results["txt2"];
this.accValue = results["txt3"];

var oRslt = dialog.store();
this.bChk1 = oRslt["Chk1"];
this.bChk2 = oRslt["Chk2"];


},

description:
{
name: "Energy Rating Information", // Dialog box title
elements:
[
{
type: "view",
elements:
[
{
name: "Enter Star Rating: ",
type: "static_text",
},
{
item_id: "txt1",
type: "edit_text",
multiline: true,
width: 300,
height: 20
},
{
name: "Enter MJ/m²: ",
type: "static_text",
},
{
item_id: "txt2",
type: "edit_text",
multiline: true,
width: 300,
height: 20
},

{
name: "Enter Accreditation Number: ",
type: "static_text",
},
{
item_id: "txt3",
type: "edit_text",
multiline: true,
width: 300,
height: 20
},

{
type: "view",
char_height: 10,
elements:
[
{
type: "static_text",
item_id: "stat",
name: "What type of rating is this?:",
char_width: 15,
alignment: "align_fill",
font: "dialog",
},
{
type: "view",
char_width: 8,
char_height: 8,
align_children: "align_top",
elements:
[
{
type: "view",
char_width: 8,
char_height: 8,
elements:
[
{
type: "check_box",
item_id: "Chk1",
name: "Single dwelling",
},
{
type: "check_box",
item_id: "Chk2",
name: "Multi-unit development",
},

]
},
]
},
]
},

{
type: "ok_cancel",
ok_name: "Ok",
cancel_name: "Cancel"
},
]
},
]
}
};


if(event.source.forReal && (event.source.stampName == "#fF_WBqLLUm0cA33ryprG3A"))
{
if ("ok" == app.execDialog(dialog))
{
var cMsg = dialog.starValue;
event.value = "\n" + cMsg;
event.source.source.info.mj = cMsg;

cMsg = "\n" + dialog.mjValue;
this.getField("MJ/m²").value = cMsg;

cMsg = "\n" + dialog.accValue;
this.getField("accreditation").value = cMsg;

}

}

I dont know how to post an image of the actual stamp or the actual pdf. Instructions on how to do this would be great too


Jorge Gutierrez


3 Answers

Voted Best Answer

You can use the this.bChk1 variable and the checkThisBox() method of the check-box field to achieve that.

-------------------------------------
Visit my custom-made PDF scripts website: http://try67.blogspot.com
Contact me personally: try6767@gmail.com


By Gilad D (try67)   

You are doing pretty good so far. Although "dialog" is not a good name for your dialog box. It's a bit too generic and it's a keyword.

Add this code to your "ok" block

this.getField("YourCheckBox1").value = dialog.bChk1?"Yes":"Off";

or

this.getField("YourCheckBox1").checkThisBox(dialog.bChk1,0);

Either method works fine.

You might be interested in my new book
All About PDF Stamps in Acrobat and Paperless Workflows
It covers using checkboxes and custom dialogs on dynamic stamps.

Thom Parker
The source for PDF Scripting Info pdfscripting.com

The Acrobat JavaScript Reference, Use it Early and Often

The most important JavaScript Development tool in Acrobat
The Console Window (Video tutorial)
The Console Window(article)

Having trouble, Why Doesn't my Script Work


Thom Parker   

Thank you to the 2 people that took the time out to help me out. I believe both of you pointed me in the right direction.

But I have to thank Mr. Parker for the actual code example, looking around all over the net your name pops up everywhere in relation to JS and stamps and Im honored to have your help. For some reason it liked the first option better.

--> this.getField("YourCheckBox1").value = dialog.bChk1?"Yes":"Off";

Im definetely going to buy your book as I like the way you explain things and provide examples. I find fillable pdf forms, user inputs and paperless workflows absolutely fascinating. Maybe up the price of the book to $25 even so that its eligible for the FREE Super Saver Shipping.

Regards and have a great day


Jorge Gutierrez   


Please specify a reason: