6 Replies Latest reply on Sep 3, 2015 3:49 AM by SandraBug

    Text in field triggers radio button?

    SandraBug Level 1

      I'm sure this is a simple one, and I'm just having a Monday moment, but I can't seem to find it by searching the forum...

       

      I'm creating a pdf form and I want a radio button to be automatically checked when someone enters text in a certain field - how best do I do this?

        • 1. Re: Text in field triggers radio button?
          MatLac Level 1

          You could test the length of the value of your field to be greater than 0 or the value to be "not equal" to an empty string?

           

          in the calculate event of your field:

           

          if (event.target.value.length > 0) this.getField("radio1").checkThisBox(0, true)

          else this.getField("radio1").checkThisBox(0, false)

           

          or

           

          if (event.target.value == "") this.getField("radio1").checkThisBox(0, false)

          else this.getField("radio1").checkThisBox(0, true)

          • 2. Re: Text in field triggers radio button?
            SandraBug Level 1

            Doesn't seem to work I'm afraid. I also causes the field itself to default to zero after inputting data in another field for some reason.

             

            Thanks heaps though MatLac! Any help is useful and appreciated 

            • 3. Re: Text in field triggers radio button?
              George_Johnson MVP & Adobe Community Professional

              Do you have more than one radio button in the radio button group, and if so, what are their values and which one do you want selected when the text field is not empty?


              • 4. Re: Text in field triggers radio button?
                SandraBug Level 1

                I do - a screen cap of the area I'm coding is below with current field values following:

                 

                Screen Shot 2015-09-02 at 1.21.40 pm.png

                 

                First option:

                Radio button: name = "stand", value = "space"

                Fields (L-R): "width1", "depth1", "size1", "rate1", "cost1", "gst1", "space1"

                 

                Second option:

                Radio button: name = "stand", value = "shell"

                Fields (L-R): "width2", "depth2", "size2", "rate2", "cost2", "gst2", "space2"

                 

                I already have all the calculations working, and the fields clear when you select the alternate radio button. Currently though, the values only clear if you select the other radio button - if you enter values in both options without clicking the radio button, all values get added to the final total.

                 

                Ultimately my aim is to have the form set up so you can only select/complete one option. Having the other option clear (and/or the appropriate radio button select) when you enter values in your chosen option.

                 

                Hope that all makes sense. Very happy for advice on the best/easiest way to do this

                • 5. Re: Text in field triggers radio button?
                  George_Johnson MVP & Adobe Community Professional

                  I would set it up so that none of the fields in either section can be filled-in unless one of the radio buttons is selected. So the floor space fields are only shown if that radio button is selected and the same with the Pre-Built-Shell Scheme fields. You can do this by showing/hiding the fields, and you'd also want to reset the fields whenever they are shown/hidden. The coding can be significantly simplified if you use a hierarchical field naming system for both groups. For example, fso.width, fso.depth, fso.area, fso.a$, etc., and pss.width, pss,depth, etc.

                   

                  You can then hide all of the Pre-Built Shell Scheme fields and reset them, and show all of the Floorspace only fields and reset them with the following:

                   

                  // Hide all of the Pre-Built Shell Scheme fields and reset them

                  getField("pss").display = display.hidden;

                  resetForm(["pss"];

                   

                  // Hide all of the Floor space only fields and reset them

                  getField("fso").display = display.visible;

                  resetForm(["fso"];

                   

                   

                  This isn't complete but should get you started. Note that you could set up the A$ fields so they are automatically calculated based on the Total m2 field value, so the user doesn't have to enter it and perhaps make a mistake. You can also set up the calculated fields to display a value only if the width and depth fields are complete.

                  • 6. Re: Text in field triggers radio button?
                    SandraBug Level 1

                    Thanks so much George_Johnson!

                     

                    There was a slight error in the syntax, but I figured it out and it works beautifully...

                     

                    For reference of anyone in future searching through these forums, the code I ended up using is as follows - following the hierarchial naming convention suggested above:

                     

                    // First radio button:

                    getField("pss").display = display.hidden;

                    resetForm(["pss"]);

                    getField("fso").display = display.visible;

                     

                    // Second radio button:

                    getField("fso").display = display.hidden;

                    resetForm(["fso"]);

                    getField("pss").display = display.visible;

                     

                    Lovely! Thanks again