Skip to main content
Known Participant
February 19, 2018
Answered

Radio Button not being assigned a value

  • February 19, 2018
  • 1 reply
  • 1147 views

Not sure what I am doing wrong but the form is not showing the radio button value default of "No" and even if user clicks on "Yes" or "No," nothing happens (see below):

The way it is supposed to work is that if the user clicks "Yes," the DocNumber will be included in the 1) Filename Preview and 2) Saved Filename.  Here are excerpts of the code (I tried to paste the relevant code, see red text for specific concern):

//Set Filename Preview <---This is #1 above

    function DoSetFileName(dialog, oDlg)

    {

          var oRslt = dialog.store();

          var strFileName = "";

  

               // Add Document Num

               if(oRslt["BegNum"]) <----Not working when user selects radio button with yes and I don't know why

              {

                 strFileName += oRslt["DNum"];

               }

  

               strFileName += oDlg.strFileName.replace(/\.pdf/,""); //This is the original file name with the .pdf removed                                                        

               strFileName += ".pdf"; //Add pdf back to filename

               dialog.load({"SvFl":strFileName}); //load filename in preview window

      }

//</CodeAbove>

    global.DocNumAction =

    {

      

        strDocNumInName:"NoNum", <---default value set but not defaulting to "No"

         .

        .

         .

           }

var dlgInit =

            {

                    "MrgH": this.nMarginX,

                    "MrgV": this.nMarginY,

                    "Bkgd": listBkgd,

                    "DNum": this.strInitDocNum, //Added so space after doc # (7/7/17SCS)

                    "SPst": this.bSaveWPostFx,

                    "Exmp": this.strExmp,

                    "LPfx": this.strLabelPrefix,

                    "DocN": this.bIncludeDocNum,

                    "PgNm": this.bIncludePageNum,

                    "PPfx": this.strPageNumPrefix,

                    "PPsf": this.bPageNumPostfix,

                    "tFPg": this.strStrtPg,

                    "tTPg": this.strEndPg,

                    "SvPr": this.strSavePrefix,

                    "SvPs": this.strSavePostfix,

                    "SvFl": this.strSvFl,

            };

            dlgInit[this.strHorzPos] = true;

            dlgInit[this.strVertPos] = true;

            dlgInit[this.strBoxStateSel] = true;

            dlgInit[this.strPgRangeSel] = true;

            dlgInit[this.strTotalPgNumInName] = true;

            dlgInit[this.strDocNumInName] = true;

            dialog.load(dlgInit);

            dialog.enable(

                {

                    "tTPg": false,

                    "tFPg": false,

                    "PPfx": false,

                    "DNum": false,

                }

        );

.

.

.

var exInit = {"ExPg":this.strPgRangeSel =="rFro", "DNum":this.bIncludeDocNum, "PPfx":this.bIncludePageNum,

                                   "PPsf":this.bIncludePageNum,  "MrgH":this.strHorzPos!="PosC",

                                   "SvPs":this.bSaveWPostFx ,"SvDn":this.bSaveWPostFx,"NumGrp":this.bSaveWPostFx,

                                   "tFPg":this.strPgRangeSel =="rFro", "tTPg":this.strPgRangeSel == "rFro", "rCur":!this.bHidden};

          

            dialog.enable(exInit);

            this.SetDocNumber(dialog, this);

        },

.

.

.

commit: function(dialog)

        {

            var oRslt = dialog.store();

            this.strHorzPos = this.GetRadioSel(oRslt,["PosL","PosC","PosR"]);

            this.nMarginX = oRslt["MrgH"];

            this.strVertPos = this.GetRadioSel(oRslt,["PosT","PosB"]);

            this.nMarginY = oRslt["MrgV"];

            var path = new Array();

            this.strLTyp = (this.GetListSel(oRslt["LTyp"],path))?path.reverse():"";

            var path = new Array();

            this.strBackgroundCol = (this.GetListSel(oRslt["Bkgd"],path))?path.reverse():"";

            this.strExmp = oRslt["Exmp"];

            this.strLabelPrefix = oRslt["LPfx"];

            this.bIncludeDocNum = oRslt["DocN"];

            this.strInitDocNum = oRslt["DNum"];

            this.bIncludePageNum = oRslt["PgNm"];

            this.strPageNumPrefix = oRslt["PPfx"];

            this.bPageNumPostfix = oRslt["PPsf"];

            this.strBoxStateSel = "Lckd"

            this.strPgRangeSel = this.GetRadioSel(oRslt,["rAll","rCur","rFro"]);

            this.strStrtPg = oRslt["tFPg"];

            this.strEndPg = oRslt["tTPg"];

            this.bSaveWPostFx = oRslt["SPst"];

            this.strSavePrefix = oRslt["SvPr"];

            this.strTotalPgNumInName = this.GetRadioSel(oRslt,["None","DnPr"]);

            this.strDocNumInName = this.GetRadioSel(oRslt,["NoNum","BegNum"]);

            this.strSavePostfix = oRslt["SvPs"];

            this.strSvFl = oRslt["SvFl"];

        },

        "Abrt": function(dialog)

        {

            dialog.end("Abrt");

        },

        "Skip": function(dialog)

        {

            dialog.end("Skip");

        },

        "SvPs": function(dialog)

        {

            this.SetFileName(dialog,this);

        },

        "DnPr": function(dialog)

        {

            this.SetFileName(dialog,this);

        },

        "None": function(dialog)

        {

            this.SetFileName(dialog,this);

        },

        "NoNum": function(dialog)

        {

            this.SetFileName(dialog,this);

        },

        "BegNum": function(dialog)

        {

            this.SetFileName(dialog,this);

        },

        "SvPr": function(dialog)

        {

            this.SetFileName(dialog,this);

        },

        "SPst": function(dialog)

        {

        dialog.load({"SPst": true }); //added so checkbox for Save File is disabled (SCS)

        dialog.enable({"SPst": false }); //added so checkbox for Save File is disabled (SCS)

            var bOn = dialog.store()["SPst"];

            dialog.enable({"SvPs":bOn,"SvDn":bOn,"NumGrp":bOn});

            this.SetFileName(dialog,this);

        },

.

.

.

      {

                            type: "cluster",

                            item_id: "cls1",

                            name: "FILENAME OPTIONS",

                            font: "palette",

                            bold: true,                           

                            alignment: "align_fill",

                            elements:

                            [

                               

                                {

                                    type: "view",

                                    align_children: "align_top",

                                    elements:

                                    [

                                                                          

                                        {

                                            type: "static_text",

                                            item_id: "sta9",

                                            name: "Enter Filename(or use default):",

                                        },

                                        {

                                            type: "edit_text",

                                            item_id: "SvPr",

                                            variable_Name: "strSavePrefix",

                                            width: 100,

                                            height: 23,

                                            char_width: 8,

                                            alignment: "align_fill",

                                       },

                                        {

                                           type: "static_text",

                                            item_id: "sta101",

                                            name: "Add Doc Number?:",

                                        },

                                        {

                                            type: "radio",

                                            item_id: "NoNum",

                                            group_id: "NumGrp",

                                            name: "No",

                                            variable_Name: "strDocNumInName",

                                        },

                                        {

                                            type: "radio",

                                            item_id: "BegNum",

                                            group_id: "NumGrp",

                                            name: "Yes",

                                        },

                             }    

.

.

.

// Save File <----This is #2 above

     if(global.DocNumAction.bSaveWPostFx) //if save checked

     {

         var cSavePath = oOrigDoc.path.replace(/\/[^\/]+$/,"/");

      //Add Filename

       cSavePath += global.DocNumAction.strSavePrefix; 

       cSavePath += oOrigDoc.documentFileName.replace(/\.pdf/,""); //remove .pdf from the filename

    

   //Add document number

        if(global.DocNumAction.strDocNumInName == "BegNum") <----Not working when user selects radiobutton with yes and I don't know why

        {

          cSavePath += global.DocNumAction.nCurrentDocNum;

        }

                    

        cSavePath += ".pdf"; //Add .pdf back to filename

       

        oTrgDoc.saveAs(cSavePath);

     }

Note: Using Adobe Acrobat X Pro

This topic has been closed for replies.
Correct answer Thom Parker

Since the code is incomplete and overly complex it's really hard to tell what's going on. But right off there seem to be several issues.

1. We don't all automatically know what you are doing, so you have to state up front that this code is for an Acrobat JavaScript dialog. We don't care about your project, just about the specific problem.

2. Item names are always 4 characters, no more no less. This is your main issue.

3. In the first function you're mixing contexts, not a good idea.

if you have further issues, please create a simplified dialog object that clearly demonstrates the issue. You're wasting our time by posting long partial bits of meaningless code. Most experts will simply ignore questions like this one.

1 reply

Thom Parker
Community Expert
Thom ParkerCommunity ExpertCorrect answer
Community Expert
February 19, 2018

Since the code is incomplete and overly complex it's really hard to tell what's going on. But right off there seem to be several issues.

1. We don't all automatically know what you are doing, so you have to state up front that this code is for an Acrobat JavaScript dialog. We don't care about your project, just about the specific problem.

2. Item names are always 4 characters, no more no less. This is your main issue.

3. In the first function you're mixing contexts, not a good idea.

if you have further issues, please create a simplified dialog object that clearly demonstrates the issue. You're wasting our time by posting long partial bits of meaningless code. Most experts will simply ignore questions like this one.

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
suemo22Author
Known Participant
February 19, 2018

Hi,

TY for the answer.

For #1: I am still quite a beginner so did not realize this.

For #2. I did not realize item names are always 4 characters.  Can you give me an example of what you consider to be an item name from the above code?  Do you mean item id? 

For #3: Can you give me an example of mixing contexts from the code?  I don't know what you mean.

I will keep your other comments in mind.  Thx for not ignoring my post.

Sue

Thom Parker
Community Expert
Community Expert
February 19, 2018

Yes, I meant "item_id".  You're code is quite complex for a beginner. Did you write this yourself? Did you create simpler dialogs before writing this code?

The "function DoSetFileName(dialog, oDlg)" is the function that mixes contexts. In order for "dialog" to be valid the function must be run from a function call inside the dialog definition object at dialog runtime, i.e. "oDlg". By definition oDlg is also the "this" keyword.  So why not use "this"?  This is just a style issue, unless the function exists in a different context where "this" has a different meaning, and that's where you get into trouble. You're either operating completely within the runtime dialog context (good), or your crossing context boundaries (bad).

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