3 Replies Latest reply on Aug 23, 2016 1:00 PM by gkaiseril

    One Checkbox, and one text field to determine the value of another field.

    michaelf62582725

      I have a complex form. On one page of the form I have two fields; "StdPitch" is a check or X box which can be an X or nothing at all, (marked X for a 4/12 roof pitch) and the other field "OtherPitch" which allows typing a roof pitch other than a 4/12 such as a 6/12 if the roof is not 4/12.

      If both fields are left blank or filled out, I want the "Pitch" field on the next page to show "ERROR" since the roof would typically be only 1 pitch.

      If the box is marked with an X then I want the pitch field to say 4/12 otherwise i want it to say what is typed into the other field.

      Also, the "Pitch" field the "StdPitch" field have default values "4/12" for "Pitch" and the X is marked in the "StdPitch" field because it's label show's "4/12" and that is the default.

      Here is my code, but for some reason it's not working. I've tried it setup as a Javascript Action on the "StdPitch" and the "OtherPitch" fields both, set to run on a "Blur" of the field. I've also tried it as a calculation script on the "Pitch" field.

      I cleared the "Pitch" field when someone clicks thru either of the "StdPitch" or "OtherPitch" fields when using the action script, in case my code didn't want to write over the existing value. It partially works, but not completely.

      //clear the "Pitch" field value pi.value=''

       

       

      //set the vars

      var op = this.getField("OtherPitch");

      var sp = this.getField("StdPitch").value;

      var pi = this.getField("Pitch");

       

       

      if ((op.value.length > 2) && (sp == 'Yes') || (op.value.length==0) && (sp !=     "Yes")){

          pi.value='ERROR'

      } else if ((op.value.length > 2 ) && (sp == '')) {

          pi.value=op.value

      } else if ((op.value.length==0 ) && (sp == 'Yes')) {

          pi.value=='4/12'

      }

        • 1. Re: One Checkbox, and one text field to determine the value of another field.
          gkaiseril MVP & Adobe Community Professional

          When you run your script what happens?

           

          For a check box, when not selected or "X" the value is the string "Off" with a length of 3 not a null string nor a length of zero.

           

          If you want only one or none of the 2 check boxes selected, why not create an exclusionary group? That way if one box has been selected and then one selects the other box, the first box is automatically unchecked. You need to set the Export value for each check box, widget, to a unique value.

          • 2. Re: One Checkbox, and one text field to determine the value of another field.
            michaelf62582725 Level 1

            Their is only one checkbox. the "StdPitch" box is a checkbox to mark if the pitch will be the standard 4/12 and it's export value is set to "Yes". The "OtherPitch" field is just a text field, in case the salesman wants to choose a 5/12, 6/12 or other pitch roof.

             

            Right now by default the "StdPitch" 4/12 checkbox is checked, and the "Pitch" field has 4/12 in it.

             

            If I uncheck the 4/12 and put a value in the "OtherPitch" field the "Pitch" field stays blank.

            If they both are blank, the "Pitch" field stays blank.

            If either of them is filled out by its self, the "Pitch" field stays blank.

            But, if they both get values, the "Pitch" field says "ERROR" like it's supposed to.

            • 3. Re: One Checkbox, and one text field to determine the value of another field.
              gkaiseril MVP & Adobe Community Professional

              A check box will always have a value even when unchecked.

               

              You should temporarily add some additional code to show you the values of the fields you are testing to make sure you are testing for what you think you are testing for.

               

              Many forms have a check box group with the standard options and then one for "Other". The other unlocks a text field into which one can add a custom value. If the "Other" is not selected the text field is cleared and made read only. This approach only allows the selection of a standard value or an optional value. It is something you should consider.