Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Checkboxes Not showing checked or unchecked in Dynamic Stamp

Explorer ,
Mar 03, 2023 Mar 03, 2023

Hello Members,

I have created a PDF DYNAMIC STAMP, consisting of 4 text fields and 4 checkboxes. Everything is working fine except for the checkboxes.

 

When I put data in the dialog box including the checkbox, The results of checkboxes (Checked/Unchecked) not showing up in Stamp.

 

//Checkbox Fields Name:

Check Box1

Check Box2

Check Box3

Check Box4

 

I have attached a ScreenShot of the stamp and JAVASCRIPT that I'm using now;

 

Thanks.

Software: Adobe Acrobat Pro DC.

 

 

var FormRouting = {
    return: 'cancel',
    DoDialog: function () {
        return app.execDialog(this);
    },

    bChk1: false,
    bChk2: false,
    bChk3: false,
    bChk4: false,

    str1: '',
    str2: '',
    str3: '',
    str4: '',

    initialize: function (dialog) {
        var dlgInit = {

            Chk1: this.bChk1,
            Chk2: this.bChk2,
            Chk3: this.bChk3,
            Chk4: this.bChk4,

            Str1: this.str1,
            Str2: this.str2,
            Str3: this.str3,
            Str4: this.str4,

        };

        dialog.load(dlgInit);
    },

    commit: function(dialog) {
        var oRslt = dialog.store();

        this.bChk1 = oRslt['chk1'];
        this.bChk2 = oRslt['chk2'];
        this.bChk3 = oRslt['chk3'];
        this.bChk4 = oRslt['chk4'];


        this.str1 = oRslt['str1'];
        this.str2 = oRslt['str2'];
        this.str3 = oRslt['str3'];
        this.str4 = oRslt['str4'];
    },

    description: {
        titlename: "Personal Data",align_children: "align_left", width: 500, height: 400, elements:
        [
            {
              type: "cluster", name: "Data Entry", align_children: "align_left", elements:
                [
                    // Text Field Code Below
                    {
                        type: "view", align_children: "align_row", elements:
                        [
                            {
                                type: "static_text", name: "Field 1:"
                            },
                            {
                                item_id: "str1", type: "edit_text", alignment: "align_fill", width: 400, height: 20
                            }
                        ]
                    },

                    {
                        type: "view", align_children: "align_row", elements:
                        [
                            {
                                type: "static_text", name: "Field 2:"
                            },
                            {
                                item_id: "str2", type: "edit_text", alignment: "align_fill", width: 400, height: 20
                            }
                        ]
                    },

                    {
                        type: "view", align_children: "align_row", elements:
                        [
                            {
                                type: "static_text", name: "Field 3:"
                            },
                            {
                                item_id: "str3", type: "edit_text", alignment: "align_fill", width: 400, height: 20
                            }
                        ]
                    },

                    // Check Box Field Code below
                    {
                        type: "view", align_children: "align_row", elements:
                        [
                            {
                                item_id: "Chk1", type: "check_box", alignment: "align_fill", width: 5, height: 20
                            },
                            {
                                type: "static_text", name: "CheckBox 1"
                            }
                        ]
                    },
                    
                    {
                        type: "view", align_children: "align_row", elements:
                        [
                            {
                                item_id: "Chk2", type: "check_box", alignment: "align_fill", width: 5, height: 20
                            },
                            {
                                type: "static_text", name: "CheckBox 2"
                            },
                        ]
                    },

                    {
                        type: "view", align_children: "align_row", elements:
                        [
                            {
                                item_id: "Chk3", type: "check_box", alignment: "align_fill", width: 5, height: 20
                            },
                            {
                                type: "static_text", name: "CheckBox 3"
                            },
                        ]
                    },

                    {
                        type: "view", align_children: "align_row", elements:
                        [
                            {
                                item_id: "Chk4", type: "check_box", alignment: "align_fill", width: 5, height: 20
                            },
                            {
                                type: "static_text", name: "CheckBox 4"
                            },
                        ]
                    },

                    // By Field
                    {
                        type: "view", align_children: "align_row", elements:
                        [
                            {
                                type: "static_text", name: "By: "
                            },
                            {
                                item_id: "str4", type: "edit_text", alignment: "align_fill", width: 400, height: 20
                            }
                        ]
                    },

                ]
            },
            {
                alignment: "align_right",
                type: "ok_cancel",
                ok_name: "ok",
                cancel_name: "Cancel"
            }
        ],
    },
};

if (event.source.forReal && event.source.stampName == "Sohail") {
    if ('ok' == FormRouting.DoDialog()) {
        // Checkboxes Fields
        if (FormRouting.bChk1) {
            this.getField('Check Box1').checkThisBox(0, true);
        }

        if (FormRouting.bChk2) {
            this.getField('Check Box2').checkThisBox(0, true);
        }

        if (FormRouting.bChk3) {
            this.getField('Check Box3').checkThisBox(0, true);
        }
        
        if (FormRouting.bChk4) {
            this.getField('Check Box4').checkThisBox(0, true);
        }

        // string fields

        this.getField('Field 1').value = FormRouting.str1;
        this.getField('Field 2').value = FormRouting.str2;
        this.getField('Field 3').value = FormRouting.str3;
        this.getField('By').value = FormRouting.str4;
    }
}

 

TOPICS
Create PDFs , General troubleshooting , JavaScript , PDF forms
4.7K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
1 ACCEPTED SOLUTION
Community Expert ,
Mar 03, 2023 Mar 03, 2023

There is no need for the "if" statement used to set the checkbox value. Write it like this:

        this.getField('Check Box1').checkThisBox(0, FormRouting.bChk1);
        this.getField('Check Box2').checkThisBox(0, FormRouting.bChk2);
        this.getField('Check Box3').checkThisBox(0, FormRouting.bChk3);
        this.getField('Check Box4').checkThisBox(0, FormRouting.bChk4);

 

And after looking through the code again I found your error.  In the dialog  "commit" function the item_id for the checkbox is spelled incorrectly. 

 

Here is the corrected code:

        this.bChk1 = oRslt['Chk1'];
        this.bChk2 = oRslt['Chk2'];
        this.bChk3 = oRslt['Chk3'];
        this.bChk4 = oRslt['Chk4'];

 

Note also that the "str" item_id's are also spelled wrong in the "initialize" function. There are however, not being used at this time, so it doesn't have any effect on the stamp behavior. 

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 03, 2023 Mar 03, 2023

 

There's nothing obviously wrong with the code. However, the checkboxes are only getting set in one direction. This may or may not be important. 

Here are two better variations:

 

1. 

    this.getField('Check Box1').checkThisBox(0, FormRouting.bChk1);

 

2. 

this.getField('Check Box1').value = FormRouting.bChk1?"Yes":"Off";

 

What kind of debug have you done? 

  • Is anything reported in the console window?
  • Have you used console.println() statements to report the values returned from the dialog?

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 03, 2023 Mar 03, 2023

Also, the stamp name needs to be prefixed with "#" so the full stamp name is "#Sohail"

 

The "#" tells Acrobat to run the script everytime the stamp is applied.  

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 03, 2023 Mar 03, 2023

Hello Thom, thanks for your help.


I have tried both variations, but the issue remains the same.


-Is anything reported in the console window?
No, I'm not seeing any errors in the console or Script window. 😞

 

And yes, I have added '#' to the stamp name. Thanks for letting me know. 🙂

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 03, 2023 Mar 03, 2023

There is no need for the "if" statement used to set the checkbox value. Write it like this:

        this.getField('Check Box1').checkThisBox(0, FormRouting.bChk1);
        this.getField('Check Box2').checkThisBox(0, FormRouting.bChk2);
        this.getField('Check Box3').checkThisBox(0, FormRouting.bChk3);
        this.getField('Check Box4').checkThisBox(0, FormRouting.bChk4);

 

And after looking through the code again I found your error.  In the dialog  "commit" function the item_id for the checkbox is spelled incorrectly. 

 

Here is the corrected code:

        this.bChk1 = oRslt['Chk1'];
        this.bChk2 = oRslt['Chk2'];
        this.bChk3 = oRslt['Chk3'];
        this.bChk4 = oRslt['Chk4'];

 

Note also that the "str" item_id's are also spelled wrong in the "initialize" function. There are however, not being used at this time, so it doesn't have any effect on the stamp behavior. 

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 03, 2023 Mar 03, 2023

Thank you so much, Thom, for helping me. I really appreciate the way you found the errors in my script. The corrections you sent me really work. Now my checkboxes are showing in the stamp the way I want them to.

Thanks

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 03, 2023 Mar 03, 2023

A Best Answer on my response would be helpful,

Thanks!

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 02, 2025 Sep 02, 2025
LATEST

Hi Sonny .. just wondering if you might be able to share yout script with me for the check boxes .. your stamp does exaclt what i need but i have no scripting experiance other than copy and pasting the basic from the web - and there is nothe to help me here - i dont even know where to add teh script in the form propries for the cehckbox. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines