11 Replies Latest reply: Mar 21, 2011 11:37 PM by MadMich RSS

    Conditional text

    MadMich Community Member

      I have several combo boxes with the same 3 items in each.

      one of the items = "fail"

      If  one or more combo box's = "fail" I want to pass the value to a text box and for it to remain there until none of the combo box's value = "fail".

       

      I have tried to fix it by adding a second (hiddden) text box where only the item "fail"  value is added. The only problem is that if the item "fail is removed from  all  the combo boxes the value needs to be removed from the text box. How do I do that , am i on the right track?

       

       

      Cheers for any help

        • 1. Re: Conditional text
          GKaiseril CommunityMVP

          For the custom calculation for the text field:

           

          // array of field names to check
          var aFields = ("CheckBox1", "CheckBox2", "CheckBox3");
          // clear the field's value
          event.value = '';
          // loop through the check boxes and test for 'Failed"
          for(i = 0; i < aFields.length; i++) {
             if(this.getField( aFields[i] ).value == "Failed") {
                // set event value to "{Failed"
                event.value = "Failed";
                } // end match field
             } // end loop of check boxes
           

          • 2. Re: Conditional text
            MadMich Community Member

            Your a star.

            Thanks for your speedy reply GKalseril.

            I think I've been looking at this the wrong way! I'm going to go away and play with this now.

            • 3. Re: Conditional text
              MadMich Community Member

              I had a go at this, my text does not remain as "Fail" and I get the error:

               

              this.getField(aFields[i]) is null
              9:AcroForm:Text2:Calculate
              TypeError: this.getField(aFields[i]) is null
              9:AcroForm:Text2:Calculate

               

              I placed the script in the text fields calculation script

              • 4. Re: Conditional text
                try67 CommunityMVP

                You misspelled one of the names of your form fields in the aFields array.

                Remember to pay attention to spaces, and to capitalization.

                • 5. Re: Conditional text
                  MadMich Community Member

                  I Think your right but I can't see where the problem lies!

                   

                  // custom calculation script for the text field

                   

                  // array of field names to check
                  var aFields = ("CheckBox1", "CheckBox2", "CheckBox3");
                  // clear the field's value
                  event.value = '';
                  // loop through the check boxes and test for 'Failed"
                  for(i = 0; i < aFields.length; i++) {
                  if(this.getField( aFields[i] ).value == "Failed") {
                  // set event value to "{Failed"
                  event.value = "Failed";
                  } // end match field
                  } // end loop of check boxes

                   

                  My Fields are named exactly as quoted! I tried going back to the original code but I now get an error when i copy and paste it!

                  • 6. Re: Conditional text
                    try67 CommunityMVP

                    I see now that there's a different problem. The array is badly defined. It needs to be:

                    var aFields = ["CheckBox1", "CheckBox2", "CheckBox3"];

                     

                    Also, I think there's a logical error in your code. Since you want to check if any of the fields has the "Failed" value you should break the loop once you discover that one of them has that value. Otherwise, you're in effect only checking the last field. So your code should actually be:

                     

                    // array of field names to check
                    var aFields = ["CheckBox1", "CheckBox2", "CheckBox3"];
                    // clear the field's value
                    event.value = '';
                    // loop through the check boxes and test for 'Failed"
                    for(i = 0; i < aFields.length; i++) {
                    if(this.getField( aFields[i] ).value == "Failed") {
                    // set event value to "Failed" and stop
                    event.value = "Failed";

                    break;
                    } // end match field
                    } // end loop of check boxes

                    • 7. Re: Conditional text
                      MadMich Community Member

                      Thanks alot that worked a treat.

                      • 8. Re: Conditional text
                        MadMich Community Member

                        Hi another question,

                        If I deselct "fail" in the Combo Box, the text field does not change?

                        I have to reselct the item in the combo box again before it will change.

                        • 9. Re: Conditional text
                          try67 CommunityMVP

                          Make sure the text field is calculated after the combo-boxes.

                          Here's how to edit it:

                          - Go to Forms - Edit form in Acrobat

                          - Go (again) to Forms - Edit Fields - Set Field Calculation Order

                          • 10. Re: Conditional text
                            MadMich Community Member

                            I didn't know you could do that.

                            But my problem is still there.

                             

                            I have two text fields, text field 1 (hidden) has the calculation  script and text field 2 poulates via a document leve script as follows:

                             

                            function Approval()
                            {

                             

                            if (!event.willCommit) {
                            var c = this.getField("Text2");
                            var f = this.getField("Text1");

                             

                            switch (event.change) {
                            case "Fail":
                            c.value = "Fail";
                            f.value = "Fail";
                            break;
                            case "Minor Deviation":
                            c.value = "Yes"
                            break;
                            case "Observation":
                            c.value = "Yes";
                            break;
                            case " ":
                            c.value = " ";
                            }
                            if (f.value == "Fail"){
                            c.value = "Fail"
                            }
                            }}

                             

                             

                            I think i probably have the whole thing too complicated! I'd prefer to get rid of the hidden field if possible.

                            • 11. Re: Conditional text
                              MadMich Community Member

                              I think i've fixed it based on the calculation order you mentioned.

                              Basically i've added  a calculation to the second text box based on the result of the first text box like this:

                               

                              if (f.value == "Fail"){
                              c.value = "Fail"
                              }else{
                              c.value = event.value
                              }

                               

                              This enbabled me to strip the same information from the document level script.
                              Phew! Sound like a scripter!