7 Replies Latest reply on Feb 25, 2009 11:13 AM by (Scott_C_Clark)

    how to linking a textfield to another when checkbox is checked.

      HI All

      Can Anybody please help me;)

      I want to do the following: I have to textfileds in a pdf form. Next to the second textfiled is a checkbox. I want to have the second textfiled to be linked to the first one only when the checkbox is checked.

      So when the checkbox is checked, the second textfiled should have the same value as the first textfield. Whe the checkbox is not checked The second textfiled can be overwritten and has its own value.

      This is my try:

      var g = this.getField("checkbox1");

      if(g.isBoxChecked(1))
      {

      var f = this.getField("Text1");
      event.value = f.value;
      }

      Now the if statement doesn´t work. But when i just have this:

      var f = this.getField("Text1");
      event.value = f.value;

      It works fine, and both textfiled s have the same value.

      Can anybody please help me?;)
      I am searching the whole net now for 2 days and haven´t found anything usefull. I also didn´t find anything in the adobe documentations and sample pdf files:(

      Thanks for any hint;)

      cheers dietmar
        • 1. Re: how to linking a textfield to another when checkbox is checked.
          You add some JavaScript to the check boxes on blur action to copy the necessary form fields to or clear them. Using Acrobat Forms:

          //Replace the "Text1 or Text2" with whatever you named your text boxes

          // clear the fields - assume not checked
          this.getField("Text2").value = '';

          // check for checked
          if(event.value != 'Off') {
          this.getField("Text2").value =
          this.getField("Text1").value;
          } // end of if checked
          • 2. Re: how to linking a textfield to another when checkbox is checked.
            MarkWalsh Level 4
            IMHO, anything that wipes out user-entered data is not a good practice. If the user changes their mind, or clicked the wrong field, then what was entered into Text2 is deleted unexpectedly.

            Perhaps you could use a third field set to read only for the calculation, and hide or show the entry field based on the checkbox being clicked.

            This entered into the 'MouseUp' event for the checkbox field:

            if(this.getField("CheckBox1").value != 'Off') {
            this.getField("EntryField1").display = display.visible;
            this.getField("Calculate").display = display.hidden;
            } else {
            this.getField("EntryField1").display = display.hidden;
            this.getField("Calculate").display = display.visible;
            }

            and you can set the Calculate Field to:

            this.getField("EntryField2").value
            • 3. Re: how to linking a textfield to another when checkbox is checked.
              MarkWalsh Level 4
              Update: Quick testing indicates that the calculated field doesn't always change with the EntryField2, so instead of the Calculate field script, you could update it with this in the Blur event of the EntryField2:

              this.getField("Calculate").value = this.getField("EntryField2").value
              • 4. Re: how to linking a textfield to another when checkbox is checked.
                Level 1
                Thanks so much both of you;)

                NOw it works great, the only problem i have to solve now is, how can i get the textfield writeprotected when the textfield 2 has the value of textfield 1?

                Thanks, again

                cheers dietmar
                • 5. Re: how to linking a textfield to another when checkbox is checked.
                  Level 1
                  Ok again me;)

                  I found out how this works,m for all the people that where searching for the same solution;)

                  And i have added some code that will only clear the value of Textfiled 2 when it is not linked to the other one. So when both textfields have the same value and you check off the check box the textfiled2 will be cleared. Otherwise if both Textfield have different vaalues (so content was entered already) it will not clear)

                  // check for checked
                  if(this.getField("CheckBox1").value != 'Off') {
                  this.getField("Text2").value =
                  this.getField("Text1").value;

                  //when checked make field read only
                  var h = getField("Text2");
                  h.readonly = true;
                  } // end of if checked

                  else
                  {
                  //when not checked make field read and write
                  var i = getField("Text2");
                  i.readonly = false;

                  // clear the field Text2 only when values of both textfields are equal.
                  if
                  (this.getField("Text2").value ==
                  this.getField("Text1").value)
                  {

                  this.getField("Text2").value = ''; }

                  }

                  Thanks for all your help, and hope this helps some more people:)

                  cheers dietmar
                  • 6. Re: how to linking a textfield to another when checkbox is checked.
                    Level 1
                    I would like to do something similar to this.
                    But what I would like to do is have one field called "Part Number #" and link it to another called "Description #" So when I choose a particular part number the associated description to it shows up in the description field.

                    Thanks in advance for any help.
                    • 7. Re: how to linking a textfield to another when checkbox is checked.
                      Corey,
                      Use a combo box with the part number and a switch statement (on blur, and commit immediately) linked to several text fields for the description. Something like this:

                      var combo1 = this.getField("Combo Box5").value;
                      var endDefault;
                      var a = this.getField("Text1")
                      var b = this.getField("Text2")
                      var c = this.getField("Text3")

                      switch (combo1){

                      case "Select an address":
                      getField("Text1").value = "",
                      getField("Text2").value = "",
                      getField("Text3").value = "";
                      break;

                      case "Part #1":
                      getField("Text1").value = "Part #1 Description",
                      getField("Text2").value = "Line break 1 description",
                      getField("Text3").value = "Line break 2 description";
                      break;

                      case "Part #2":
                      getField("Text1").value = "Part #2 Description",
                      getField("Text2").value = "Line break 1 description",
                      getField("Text3").value = "Line break 2 description";
                      break;

                      case "Part #3":
                      getField("Text1").value = "Part #3 Description",
                      getField("Text2").value = "Line break 1 description",
                      getField("Text3").value = "Line break 2 description";
                      break;

                      default:
                      endDefault = false;

                      }
                      if (endDefault = false)
                      app.alert("Please select from the drop-down menu",3);