14 Replies Latest reply on Jul 15, 2011 2:36 PM by KU#1N08

    Copy contents of one text field to another when a radio button is checked

    KU#1N08 Level 1

      Would like one text field to autofill with the contents of a previous text field if a certain radio button is checked. Here is the script I've attempted, but it's not working.

       

      //Mouse Up JavaScript for radio button;
      ("P1 Selling Office").value = ("P1 Listing Company").value === "INO Inner Office" ? true : false;

        • 1. Re: Copy contents of one text field to another when a radio button is checked
          BarlaeDC Level 4

          HI,

           

          I think the code would need to be something like this

           

          Assuming

          "INO Inner Office" is the radio button group

          "P1 Listing Company" is the textfield to copy from

          "P1 Selling Office" is the textField to copy to

           

          if ( this.getField("INO Inner Office").value == "Yes")

          {

              this.getField("P1 Selling Office").value = this.getField("P1 Listing Company").value

          }

          else

          {

               // blank the text field if another option is selected.

              this.getField("P1 Selling Office").value = "";

          }

           

           

          Hope this helps

           

          Malcolm

          • 2. Re: Copy contents of one text field to another when a radio button is checked
            KU#1N08 Level 1

            Thank you . . . I'll give this a try. I hate to appear complete inept, but I'm very new at this. Would I put this in the properties for the radio button?

             

            Denise

            Denise A. Humphrey

            Event Coordinator/Bookkeeper

            Topeka Area Association of REALTORS®, Inc.

            Phone: 785/267-3215

            Fax: 785/267-4993

            • 3. Re: Copy contents of one text field to another when a radio button is checked
              KU#1N08 Level 1

              This is what I put in the properties for the radio button:

               

              //Mouse Up Javascript for radio button;
              if ( this.getField("INO Inner Office").value == "Yes"){
                  this.getField("P1 Selling Office").value = this.getField("P1 Listing Company").value } else {
                   // blank the text field if another option is selected.
                  this.getField("P1 Selling Office").value = "";}

               

              It doesn't seem to be working. >:o(

              • 4. Re: Copy contents of one text field to another when a radio button is checked
                gkaiseril MVP & Adobe Community Professional

                Are you getting any error messages in the JavaScript debugging console?

                 

                I would use a check box and not a radio button, as a radio button can not be deselected.

                 

                //Mouse Up JavaScript ;
                try {
                var vINO = this.getField("INO Inner Office").value;
                } catch(e) {
                app.alert("Error accessing INO Inner Office:\n" + e.toString(), 1, 0);
                }

                try{
                var oSellingOffice = this.getField("P1 Selling Office");
                var cSellingOffice = oSellingOffice.value;
                } catch(e) {
                app.alert("Error accessing P1 Selling Office:\n" + e.toString(), 1, 0);
                }

                try{
                var oListingOffice = this.getField("P1 Listing Company");
                var cListingOffice = oListingOffice.value;
                } catch(e) {
                app.alert("Error accessing P1 Listing Office:\n" + e.toString(), 1, 0);
                }

                switch(vINO) {
                case "Off":
                app.alert("Clearing Selling Office", 2, 0);

                oSellingOffice.value = "";
                break;
                case "Yes":

                app.alert("Copying value form Listing Office to Selling Office", 2, 0);
                oSellingOffice.value = oListingOffice.value;
                break;
                default:
                app.alert("Unknown value for \"INO Inner Office\" field: " + vINO, 1, 0);
                break;
                }

                • 5. Re: Copy contents of one text field to another when a radio button is checked
                  KU#1N08 Level 1

                  No . . . I don't get any error messages.

                   

                  I have to use a radio button because there are multiple options, of which only one is allowed. It is a required field, so something has to be checked.

                   

                  Denise

                  Denise A. Humphrey

                  Event Coordinator/Bookkeeper

                  Topeka Area Association of REALTORS®, Inc.

                  Phone: 785/267-3215

                  Fax: 785/267-4993

                  • 6. Re: Copy contents of one text field to another when a radio button is checked
                    gkaiseril MVP & Adobe Community Professional

                    Have you tried the script provided?

                     

                    What are the other options and the export value for each option?

                     

                    What action do you want taken for each option?

                     

                    What other actions should be included for each option?

                     

                    Do you need testing for unknown values?

                     

                    You will need to have this script run for each of radio buttons in the group or you may get different results that what is expected and make it very hard for another person to update the form . In which case, I would use a document level function and call that function within each radio button.

                     

                    The "===" is strict logical comparison operator and you might want to use the "==" equality operator.

                    • 7. Re: Copy contents of one text field to another when a radio button is checked
                      BarlaeDC Level 4

                      HI,

                       

                      The only thing that is obvious that it could be is that the export value for the radio button "INO Inner Office" is not set to be "Yes".

                       

                      If you open the radio button properties and select the "Options" Tab and make sure "Radio Button Choice" is set to "Yes"

                       

                      OR

                       

                      If you want it to be different then change the "Yes" in the script to whatever the valud of the "Radio Button Choice" is

                       

                      Hope this helps

                       

                      Malcolm

                      • 8. Re: Copy contents of one text field to another when a radio button is checked
                        KU#1N08 Level 1

                        ARRRRRGGGGGHHHHHH!!!! People who don't know scripting (i.e., ME!!!) shouldn't attempt to do it!

                         

                        I changed the script to reflect the export value of the radio button, but it's still not working. Tried it in the properties for both the text box and the radio button, but still no luck. Oh well . . . I'm going with it the way it is.

                         

                        I truly appreciate all your help!! Have a great day!

                         

                        Denise

                        Denise A. Humphrey

                        Event Coordinator/Bookkeeper

                        Topeka Area Association of REALTORS®, Inc.

                        Phone: 785/267-3215

                        Fax: 785/267-4993

                        • 9. Re: Copy contents of one text field to another when a radio button is checked
                          Insane_ai_0101

                          I am completely new to JavaScript and Adobe Acrobat creation but have been programming in VBA and VBScript for over 5 years.  I have created a form in Acrobat 9 Professional with three address blocks: Pickup Address, Mailing Address and Billing Address.  In some cases, these are different addresses but in most, they are all the same.  I would like to have a checkbox to copy the Pickup Address information to the other blocks; if I get this working I will create a similar script for the billing address.  I have tried to follow the example in this thread but I am receiving Syntax Error 24: at Line 25 in the following script:

                           

                          Basic Properties of the checkbox:

                          Name: chkCopyToMail

                          Style: Check

                          Export Value: "Yes" (No quotes in the property field)

                          Trigger: Mouse Up

                          Action: "Run a JavaScript"

                          All other properties are default.

                           

                          I have a few questions about what is going on in the script and a varied result.

                           

                          1.  Why use the two variables to get one text field value?  (Example from this thread uses oSellingOffice and cSellingOffice)

                          2.  Why are the values for the checkbox "Off" and "Yes", are these defaults?  I have the Export Value set to Yes to ensure compliance with the script.

                          3.  Is my interpretation of the script activity correct?

                               a. Read the current value of the checkbox

                               b. Collect data from the source fields with error capture

                               c. Collect data from the destination fields with error capture

                               d. Toggle the value of the checkbox

                               e. Interpret the value of the checkbox and change the destination fields to the stored source values or clear them as is appropriate.

                          4.  Following the example in this post a bit more closely, I also eliminated the blank lines between the lines of code. This produced Syntax Error 21: at Line 22.   This error is still triggering the same line of code as the Syntax Error 24: "app.alert("Error accessing Pickup City:\n" + e.toString(), 1, 0);"

                           

                          Googling JavaScript Errors / Sytax Error 24 + JavaScript + Acrobat have not yeilded anything of value.   Your help is greatly appreciated.

                           

                          //Copy Pickup Address to Mailing Address ;
                          try{
                          var vchkCopyMail = this.getField("chkCopyToMail").value;
                          } catch(e) {
                          app.alert("Error Accessing chkCopyToMail:\n" + e.toString(),1, 0);
                          }

                          try{
                          var oPadd1 = this.getField("PickupAdd1");
                          var cPAdd1 = oPadd1.value;
                          } catch(e) {
                          app.alert("Error accessing Pickup Address 1:\n" + e.toString(), 1, 0);
                          }

                          try{
                          var oPadd2 = this.getField("PickupAdd2");
                          var cPAdd2 = oPadd2.value;
                          } catch(e) {
                          app.alert("Error accessing Pickup Address 1:\n" + e.toString(), 1, 0);
                          }

                          var oPCity = this.getField("PickupCity");
                          var cPCity = oPCity.value;
                          } catch(e) {
                          app.alert("Error accessing Pickup City:\n" + e.toString(), 1, 0);
                          }

                          var oPState = this.getField("PickupState");
                          var cPState = oPState.value;
                          } catch(e) {
                          app.alert("Error accessing Pickup State:\n" + e.toString(), 1, 0);
                          }

                          var oPZip = this.getField("PickupZip");
                          var cPZip = oPZip.value;
                          } catch(e) {
                          app.alert("Error accessing Pickup Zip:\n" + e.toString(), 1, 0);
                          }

                          try{
                          var oMadd1 = this.getField("MailingAdd1");
                          var cMAdd1 = oMadd1.value;
                          } catch(e) {
                          app.alert("Error accessing Mailing Address 1:\n" + e.toString(), 1, 0);
                          }

                          try{
                          var oMadd2 = this.getField("MailingAdd2");
                          var cMAdd2 = oMadd2.value;
                          } catch(e) {
                          app.alert("Error accessing Mailing Address 1:\n" + e.toString(), 1, 0);
                          }

                          var oMCity = this.getField("MailingCity");
                          var cMCity = oMCity.value;
                          } catch(e) {
                          app.alert("Error accessing Mailing City:\n" + e.toString(), 1, 0);
                          }

                          var oMState = this.getField("MailingState");
                          var cMState = oMState.value;
                          } catch(e) {
                          app.alert("Error accessing Mailing State:\n" + e.toString(), 1, 0);
                          }

                          var oMZip = this.getField("MailingZip");
                          var cMZip = oMZip.value;
                          } catch(e) {
                          app.alert("Error accessing Mailing Zip:\n" + e.toString(), 1, 0);
                          }


                          Switch(vChkCopyMail) {
                          case "Off":
                          app.alert("Clearing Mailing Address", 2, 0);

                          oPadd1.value = "";
                          oPadd2.value = "";
                          oPCity.Value = "";
                          oPState.value = "";
                          oPZip.value = "";
                          break;

                          Case "Yes":
                          app.alert("Copying values from Generator Address to Mailing Address", 2, 0);
                          oMadd1.Value = oPAdd1;
                          oMadd2.value = oPadd2;
                          oMCity.value = oPCity;
                          oMState.value = oPState;
                          oMZip.value = oPZip;
                          break;
                          default:
                          app.alert("Unknown value for \"chkCopyToMail\" field: " + vchkCopyMail, 1 , 0);
                          break;
                          }

                          • 10. Re: Copy contents of one text field to another when a radio button is checked
                            George_Johnson MVP & Adobe Community Professional

                            1. oSellingOffice is a field object and cSelling office is its value.

                             

                            2. When a check box is not selected, its value is "Off". When it's selected, its value is whatever you set the export value to. Acrobat defaults to "Yes" when you create a new one.

                             

                             

                            Also, since JavaScript is case sensitive, you need to use "switch" and not "Switch".

                            • 11. Re: Copy contents of one text field to another when a radio button is checked
                              Insane_ai_0101 Level 1

                              My issue is now solved. 

                              Problems with my code:

                              Switch instead of switch   -   Thanks George

                              Case "Yes":  instead of case "Yes":

                              And mulitple missing try{ statements in the try/catch statements.

                               

                              Thanks for all of your help.  Here is a copy of the working code for anyone who wants to use it as a reference:

                              //Copy Pickup Address to Mailing Address ;
                              try{
                              var vchkCopyMail = this.getField("chkCopyToMail").value;
                              } catch(e) {
                              app.alert("Error Accessing chkCopyToMail:\n" + e.toString(),1, 0);
                              }
                              try{
                              var oPadd1 = this.getField("PickupAdd1");
                              var cPAdd1 = oPadd1.value;
                              } catch(e) {
                              app.alert("Error accessing Pickup Address 1:\n" + e.toString(), 1, 0);
                              }
                              try{
                              var oPadd2 = this.getField("PickupAdd2");
                              var cPAdd2 = oPadd2.value;
                              } catch(e) {
                              app.alert("Error accessing Pickup Address 1:\n" + e.toString(), 1, 0);
                              }
                              try{
                              var oPCity = this.getField("PickupCity");
                              var cPCity = oPCity.value;
                              } catch(e) {
                              app.alert("Error accessing Pickup City:\n" + e.toString(), 1, 0);
                              }
                              try{
                              var oPState = this.getField("PickupState");
                              var cPState = oPState.value;
                              } catch(e) {
                              app.alert("Error accessing Pickup State:\n" + e.toString(), 1, 0);
                              }
                              try{
                              var oPZip = this.getField("PickupZip");
                              var cPZip = oPZip.value;
                              } catch(e) {
                              app.alert("Error accessing Pickup Zip:\n" + e.toString(), 1, 0);
                              }
                              try{
                              var oMadd1 = this.getField("MailingAdd1");
                              var cMAdd1 = oMadd1.value;
                              } catch(e) {
                              app.alert("Error accessing Mailing Address 1:\n" + e.toString(), 1, 0);
                              }
                              try{
                              var oMadd2 = this.getField("MailingAdd2");
                              var cMAdd2 = oMadd2.value;
                              } catch(e) {
                              app.alert("Error accessing Mailing Address 1:\n" + e.toString(), 1, 0);
                              }
                              try{
                              var oMCity = this.getField("MailingCity");
                              var cMCity = oMCity.value;
                              } catch(e) {
                              app.alert("Error accessing Mailing City:\n" + e.toString(), 1, 0);
                              }
                              try{
                              var oMState = this.getField("MailingState");
                              var cMState = oMState.value;
                              } catch(e) {
                              app.alert("Error accessing Mailing State:\n" + e.toString(), 1, 0);
                              }
                              try{
                              var oMZip = this.getField("MailingZip");
                              var cMZip = oMZip.value;
                              } catch(e) {
                              app.alert("Error accessing Mailing Zip:\n" + e.toString(), 1, 0);
                              }
                              switch(vChkCopyMail) {
                              case "Off":
                              app.alert("Clearing Mailing Address", 2, 0);
                              oPadd1.value = "";
                              oPadd2.value = "";
                              oPCity.Value = "";
                              oPState.value = "";
                              oPZip.value = "";
                              break;
                              case "Yes":
                              app.alert("Copying values from Generator Address to Mailing Address", 2, 0);
                              oMadd1.Value = oPAdd1;
                              oMadd2.value = oPadd2;
                              oMCity.value = oPCity;
                              oMState.value = oPState;
                              oMZip.value = oPZip;
                              break;
                              default:
                              app.alert("Unknown value for \"chkCopyToMail\" field: " + vchkCopyMail, 1 , 0);
                              break;
                              }

                               

                              Message was edited by: Insane_ai_0101

                              • 12. Re: Copy contents of one text field to another when a radio button is checked
                                Insane_ai_0101 Level 1

                                Correction:

                                My issue is partially solved:

                                The script debugger accepted my code but the destination fields are not populating.

                                None of the error messages are showing up so I think the data is collected properly.

                                In VBA, I use the refresh function after doing something like this.  I need to work on this some more.

                                 

                                 

                                Thanks again for your help!

                                • 13. Re: Copy contents of one text field to another when a radio button is checked
                                  gkaiseril MVP & Adobe Community Professional

                                  Is this code being executed by every radio button?

                                   

                                  You will need to either create a document level function and call that function is each radio button or copy the code to every radio button each time you correct the code.

                                   

                                  It might be easier to add a check box to select a copy of the field and try for less automation.

                                  • 14. Re: Copy contents of one text field to another when a radio button is checked
                                    KU#1N08 Level 1

                                    No . . . just the INO button. I may just scrap the whole thing and start over from scratch.

                                     

                                     

                                    Denise

                                    Denise A. Humphrey

                                    Event Coordinator/Bookkeeper

                                    Topeka Area Association of REALTORS®, Inc.

                                    Phone: 785/267-3215

                                    Fax: 785/267-4993