Skip to main content
ChristianBahnsen
Inspiring
November 22, 2016
Answered

acrobat xi -- return the value of the radio button selected in a custom dialog (TypeError: this.getElementById is not a function)

  • November 22, 2016
  • 1 reply
  • 2432 views

I've built a custom dialog that's rendering fine.  I emulated some code I found here in the forum, but I'm getting the following error:

TypeError: this.getElementById is not a function

Presumably I need to replace the "this.getElementById" with some other mechanism to return the value of the radio button selected.

Here's the code as it currently stands:

var oDlg =

{

   description:

   {

      name: "Save document to which folder?",

      elements:

      [

         {

            type: "cluster",

            name: "Choose a folder",

            elements:

            [

             //{

             // type: "static_text",

             // name: "Save document to which folder?: "

             //},

             {

              type: "radio",

              item_id: "rd01",

              group_id: "rado",

              name: "completed folder",

              value: "complete",

             },

             {

              type: "radio",

              item_id: "rd02",

              group_id: "rado",

              name: "need guidance",

              value: "needGuidance",

             },

             {

              type: "radio",

              item_id: "rd03",

              group_id: "rado",

              name: "no action needed",

              value: "noActionNeeded",

             },   

             {

                  type: "ok_cancel",

               },

           ]        

         },

      ]

   }

};

// Dialog Activation

app.execDialog(oDlg)

{

if (this.getElementById('rd01').checked) {

  destinationFolder = this.getElementById('rd01').value;

  }

else if (this.getElementById('rd02').checked) {

  destinationFolder = this.getElementById('rd02').value; 

  }

else if (this.getElementById('rd03').checked) {

  destinationFolder = this.getElementById('rd03').value;

  }

};

app.alert(destinationFolder,4);

Thanks

Christian Bahnsen

This topic has been closed for replies.
Correct answer ChristianBahnsen

That article was somewhat helpful as is Example 2 for execDialog in the js_api_reference.  I need to return the value of the radio button that was selected, and the examples either don't show how to do that or I'm not proficient enough at javascript to figure it out myself.

As near as I can tell, the answer lies somewhere in the dialog.store().  Radio buttons have a group_id.  Ideally the group_id should be able to return the value of the button chosen, but I can't figure out how to do it and I can't find any detailed information of working with the Dialog object.

Below is my current code (annotated to show code I'm unsure of), refactored to use the commit handler and patterned after Example 2 for execDialog in the js_api_reference.  Again, my goal is to return the value of whatever radio button was selected.

var oDlg =
{  strName: "", // a variable to hold our choice?
   initialize: function(dialog) {
// set a default radio button, just as a test -- the default is the first radio button
dialog.load({"rd02": true});},
   commit: function(dialog) {
  var results = dialog.store();  // I'm not sure what dialog.store is supposed to do
  // I tried putting a string in the parens, but it doesn't seem to do anything
  // moreover, at the last line in this script I'm getting "ReferenceError: results is not defined"
  // ideally, it would store the value of the radio group
  this.strName = results["rado"];
  app.alert(this.strName);
  },
// I'm not convinced that this whole code block is necessary
getRadioSelection: function(results) {
  for ( var i=1; i<=3; i++) {
   if ( results["rd0"+i] ) {
    switch {
     case 1:
      var myResult = "complete";
      break;
     case 2:
      var myResult = "needGuidance";
      break;
     case 3:
      var myResult = "noActionNeeded";
    }
   }
  };
  return myResult;
}, // end of the code block that seems unnecessary
   description:
   {
      name: "Save document to which folder?",
      elements:
      [
         {
            type: "cluster",
            name: "Choose a folder",
            elements:
            [
             {
              type: "static_text",
              name: "a static text string"
             },
             {
              type: "radio",
              item_id: "rd01",
              group_id: "rado",
              name: "completed folder",
              value: "complete",
             },
             {
              type: "radio",
              item_id: "rd02",
              group_id: "rado",
              name: "need guidance",
              value: "needGuidance",
             },
             {
              type: "radio",
              item_id: "rd03",
              group_id: "rado",
              name: "no action needed",
              value: "noActionNeeded",
             },   
             {
                  type: "ok_cancel",
               },
           ]        
         },
      ]
   }
};

var retn = app.execDialog(oDlg);
app.alert(retn,4);
app.alert(this.strName,4);
app.alert(results,4);
// I'm getting "ReferenceError: results is not defined"

The dialog box is rendering fine.  I'm just trying to get the value of the radio button the user selected.

Christian


Here's a working version

var oDlg =
{  myFolder:"",
   commit: function(dialog) { // this is a standard setup for a dialog object
  var results = dialog.store(); // store the user's selection
  // we have to examine each possiblity individually
  if (results["rd01"]) {
   this.myFolder = "complete";}
  if (results["rd02"]) {
   this.myFolder = "needGuidance";}
  if (results["rd03"]) {
   this.myFolder = "noActionNeeded";}  
  },
   description:
   {
      name: "Save document to which folder?",
      elements:
      [
         {
            type: "cluster",
            name: "Choose a folder",
            elements:
            [
             /* I'm commenting this section out because it's not necessary for this particular
    dialog box, but I don't want to forget that this static text area could be useful
    {
              type: "static_text",
              name: "a static text string"
             },*/
             {
              type: "radio",
              item_id: "rd01",
              group_id: "rado",
              name: "completed folder",
              value: "complete",
             },
             {
              type: "radio",
              item_id: "rd02",
              group_id: "rado",
              name: "need guidance",
              value: "needGuidance",
             },
             {
              type: "radio",
              item_id: "rd03",
              group_id: "rado",
              name: "no action needed",
              value: "noActionNeeded",
             },   
             {
                  type: "ok_cancel",
               },
           ]        
         },
      ]
   }
};

if ('ok' == app.execDialog(oDlg))
app.alert("Radio button selected: " + this.oDlg.myFolder,4);

1 reply

Bernd Alheit
Community Expert
Community Expert
November 22, 2016

This function is for browser JavaScript, not Acrobat.

ChristianBahnsen
Inspiring
November 22, 2016

OK

The dialog itself is rendering fine.  How do I get the value of the selected radio button via acrobat javascript?  (What's the equivalent acrobat function to getElementById?)

Bernd Alheit
Community Expert
Community Expert
November 22, 2016