Inspiring
May 14, 2023
Answered
javascript code trouble with dialog box Adobe Acrobat
- May 14, 2023
- 2 replies
- 6642 views
I have a PDF form with a text field named "Documents" and a button named "Button". When the button is clicked, a JavaScript window appears to select some values, click OK, the selected values should be returned to the text field named "Documents". This code works, but it does not return the selected values (Your ID Card, Your Name) to the text field. Can someone please help me? I am an amateur 😞
var FormRouting =
{
result:"cancel",
DoDialog: function(){return app.execDialog(this);},
bChk1:false,
bChk2:false,
initialize: function(dialog)
{
var dlgInit =
{
"Chk1": this.bChk1,
"Chk2": this.bChk2
};
dialog.load(dlgInit);
},
commit: function(dialog)
{
var thisForm = this.getField(this.name); // Add this line
var oRslt = dialog.store();
this.bChk1 = oRslt["Chk1"];
this.bChk2 = oRslt["Chk2"];
// Create a list of selected checkboxes
var selectedValues = [];
if (this.bChk1) selectedValues.push("Your ID Card");
if (this.bChk2) selectedValues.push("Your Name");
// Set the value of the "Documents" text field to the selected values
var field = thisForm.getField("Documents"); // Modify this line
if (field) {
field.value = selectedValues.join(", ");
}
},
description:
{
name: "Select",
elements:
[
{
type: "view",
elements:
[
{
type: "view",
char_height: 10,
elements:
[
{
type: "static_text",
item_id: "stat",
name: "Select",
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: "Your ID Card",
},
{
type: "check_box",
item_id: "Chk2",
name: "Your Name",
},
]
},
]
},
{
type: "ok_cancel",
},
]
}
]
}
]
}
};
FormRouting.bChk1 = false;
FormRouting.bChk2 = false;
if("ok" == FormRouting.DoDialog())
{
console.println("Chk1:" + FormRouting.bChk1);
console.println("Chk2:" + FormRouting.bChk2);
}
