10 Replies Latest reply on Dec 6, 2010 9:51 PM by Loveapples0

    Custom JavaScript code to link Check/Text boxes

    Loveapples0

      Hello. I'm creating a fillable pdf and am hoping someone can help me with coding for the the following action!

       

      I'd like a text box (FD1) to appear in a secondary text box (FD1#1) when a check box (FD1g) is selected.

      The condition is there are five text boxes (FD1-5) and only three secondary text boxes, so only three check boxes can be selected.

       

      I've attached a screen image for reference.

      Any help is appreciated.

       

      Thanks!

        • 1. Re: Custom JavaScript code to link Check/Text boxes
          maniac_coder

          I don't see the attachment anywhere associated with your post and cannot help with just the information you give. Can you elaborate a little bit on what you are trying to accomplish?

          • 2. Re: Custom JavaScript code to link Check/Text boxes
            Loveapples0 Level 1

            Hi  maniac_coder. Thanks for your reply!

             

            Here's a screen capture of the blank form and one with fields. The case has

            changed a little - not sure if it's quite as challenging. My inquiry is as

            follows,

             

            -The form user is to assign top three text boxes from 5; (FD1-5) I assume to

            change checkboxes to comboboxes (FD1c)  Then, number 1 selection would be

            placed in new text box, FD1#1.

             

            So,

            if FD1c=1, then FD1 appears in FD1#1,

            or FD4c=1, then FD1 appears in FD1#1

             

            // I assume the code appears in FD1#1

             

            or, if FD1c=2, then FD1 appears in FD2#2

             

            Very very much appreciated!!

            • 3. Re: Custom JavaScript code to link Check/Text boxes
              maniac_coder Level 1

              Maybe I've got a setting wrong in the forums but I simply cannot see your attachments. :-(  Any chance you can email them? rick .dot. larkin *at* rrd .dot. com. I'm sorry for the inconvenience!

              • 4. Re: Custom JavaScript code to link Check/Text boxes
                gkaiseril MVP & Adobe Community Professional

                You can create a free account at Acrobat.com and upload files to Acrobat.com and then 'Publish' the files and provide a link to the file.

                 

                Your JavaScript syntax is wrong.

                 

                Link Checkbox to text field output

                • 5. Re: Custom JavaScript code to link Check/Text boxes
                  Loveapples0 Level 1

                  hi. thanks for your email. I'll check out their support page. The direct

                  link is broken.

                  I'm unfamiliar with JavaScript syntax - do you have a good reference for

                  JavaScript?

                   

                  thanks,

                  Maria

                  • 6. Re: Custom JavaScript code to link Check/Text boxes
                    Loveapples0 Level 1

                    Hello,

                    Thanks again for your replies. I think it may be best to use a combo boxes instead of checkboxes.

                    The case has changed a little as follows:

                     

                     

                    The form user is to assign numbers 1-3 from 5 text boxes (FD1-5). I assume to use combo boxes with dropdown selections (FD1c). Number 1 selection would be placed in new text box, FD1#1.
                    So,
                    if FD1c=1, then FD1 appears in FD1#1,
                    or FD4c=1, then FD1 appears in FD1#1
                    I assume the code appears in FD1#1
                    or, if FD1c=2, then FD1 appears in FD2#2
                    I've attached screenshots to this post.
                    GKaiseril, you mentioned my syntax was wrong. Can you advise?
                    Many thanks.
                    Screen shot 2010-12-02 at 7.35.43 PM.png
                    Screen shot 2010-12-02 at 7.30.56 PM.png
                    • 7. Re: Custom JavaScript code to link Check/Text boxes
                      maniac_coder Level 1

                      Here's a quick-and-dirty way to do it. Paste this into the validate event on each of your combo boxes.

                       

                      var re = /^FD(\d{1})c$/;               // Assumed a single-digit number in box name, name format FD#c

                      if (re.test(event.target.name)) {      // Found what box # we're working with
                         this.getField("TFD"+event.value).value = this.getField("FD"+RegExp.$1).valueAsString;  // Copy to appropriate danger level field
                         if (event.value == "1") this.getField("HPD").value = this.getField("FD"+RegExp.$1).valueAsString;   // If #1 danger, also copy to the High Priority Danger field

                      } // end IF re.test

                       

                      I had to make some assumptions:

                      1. Your combo boxes are named FD#c, where # ranges from 1-5

                      2. Your top danger fields are named TFD# where # ranges 1-3 (corresponding to danger level)

                      3. Your highest priority danger field is named HPD (Highest Priority Danger). :-)

                       

                      Now, that doesn't take into account what happens if the user selects the same danger priority in multiple combo boxes. I can cook you up something to deal with that if needed. Personally, I'd think that the cat's meow would be to have the system automatically adjust any other selected danger levels if I choose a duplicate -- for example, if I have already chosen 1-3 in various fields, then choose 2 in either a new/blank field OR the former #3 value, the system would go through and adjust the prior values down a step (3->blank, 2->3, unless I'm changing 3 to 2, then I'd want 2 to automatically go to 3). Something like that.

                       

                      LMK if the above works for you or if you're interested in something a little more complex.

                      • 8. Re: Custom JavaScript code to link Check/Text boxes
                        maniac_coder Level 1

                        One other thought on my post. To shorten the code, I used string concatenation right inside the this.getField(...) calls. Normally in my code I'll do the string concatenation separately and assign to a variable, then use the variable inside the this.getField() calls. So, I guess that I'm saying that if the contat doesn't work directly in the call, assign the value to a variable then use the variable in the call, which I know will work. (I didn't have a form to test the code against so I didn't get a chance to test and see if the contact works the way it's written -- sorry. It *should* work, but as always, the proof is in the pudding as they say.)

                        • 9. Re: Custom JavaScript code to link Check/Text boxes
                          Loveapples0 Level 1

                          Hey maniac coder,

                           

                          thanks so much for your message. So, turns out this is way over my

                          head! would you be willing to code the form for a small fee?

                           

                          Thanks so much,

                          Maria

                          • 10. Re: Custom JavaScript code to link Check/Text boxes
                            Loveapples0 Level 1

                            ps.did I mention it would really really help me out!

                            hope you're willing.

                             

                            thanks.

                            Maria

                             

                             

                            On Tue, Dec 7, 2010 at 12:16 AM, Maria Kanellopoulos <