4 Replies Latest reply on Jun 19, 2012 1:59 PM by CustodyHelp

    simple if statement for a checkbox

    CustodyHelp

      Hello,

       

      Hello, I need help with some code to do the following: add an if statement to a checkbox, which makes the check box to be checked only if 2 other checkboxes are checked.. any help would be appreciated..

       

      And where would I place the code.. under the "mouse up" trigger?

       

      Thanks

        • 1. Re: simple if statement for a checkbox
          gkaiseril MVP & Adobe Community Professional

          Have you thought about what action will cause those 2 other check boxes' values to be checked?

           

          If you set a field as read only, then one can not enter data into it. The calculate, validation, and format actions will be processed but no other actions of the field will be processed.

           

          If a users skips that check box either on purpose or because it is read only none of the actions for that check box will be processed. There is no calculate, format, or validation action for a check box.

           

          You need a script for each of the other 2 check boxes to perform this task, and I would select the mouse up action.

           

          Since I will use some common code for 2 or more fields, I will use a document level JavaScript to perform the shared code, and then call that function in each check boxes mouse up action and modify the functions parameters as needed .

           

          The document level function:

           

          function AllChecked(aFields) {

          // check if all fields do not have a value of "Off"

          // logical result of test

          var bResult = true;

          // value of field being processed

          var cValue;

          // process fields

          for (i = 0; i < aFields.length; i++) {

          // get value of field to process

          cValue = this.getField(aFields[i]).value;

          // set logical result for test of the field's value not equal to "Off"

          bResult =  bResult & cValue != "Off";

          } // end processing loop for fields

          return bResult;

          } // end of AllChecked function

           

          Assuming you have 3 check boxes named "Check Box1", "Check Box2", "Check Box3". and "Check Box3" will be updatable only if both "Check Box1" & "Check Box2" were checked. The 'Mouse Up" action for "Check Box1" would be:

           

          // since the AllCehcked function returns a logical true if all fields are checked

          // take the logical not of the result for setting the RO property.

          this.getField("Check Box3").readonly = AllChecked([event.target.name, "Check Box2"]);

           

          And the same action for "Check Box2" would be:

           

          // since the AllCehcked function returns a logical true if all fields are checked

          // take the logical not of the result for setting the RO property.

          this.getField("Check Box3").readonly = AllChecked([event.target.name, "Check Box1"]);

          • 2. Re: simple if statement for a checkbox
            CustodyHelp Level 1

            Hello GKaiseril,

             

            THanks for the help, sorry for the delayed response, but I'm having a hard time adding the document level function, I have tried the wizard but I'm not getting it to work, with acrobat x pro, if you could help me with this that would be great..

             

             

            Thanks

            • 3. Re: simple if statement for a checkbox
              gkaiseril MVP & Adobe Community Professional

              The Wizard only attempts to add form fields. It does not provide any scripting.

               

              You will need Acrobat Professional to be able to edit docuement level scripts.

              • 4. Re: simple if statement for a checkbox
                CustodyHelp Level 1

                Hello GKaiseril,

                 

                Thanks for the help, but the thing I need to do is a slight modification of what it was before.. So here is the situation..

                 

                First question to determine who user is defining a visitation plan for, them or other party..

                1. Is Visitation plan for You <checkbox> or  Other Party <checkbox>

                 

                Second question is to determine Who they they were or "You" above was, either Petitioner or Respondent.

                 

                2. Were you the Petitioner or Respondent?  Petitioner <checkbox> or  Respondent <checkbox>

                 

                Next is to check the box that needs to be checked..

                 

                3. Visitation plan is for Petitioner <checkbox> or Respondent <checkbox>

                 

                Petitioner in #3 would get checked if, You is checked in #1, and Petitioner is checked in #2

                Respondent #3 would get checked if, You is checked in #1, and Respondent is checked in #2

                 

                or

                Petitioner in #3 would get checked if, Other Party is checked in #1, and Respondent is checked in #2

                Respondent in #3 would get checked if, Other Party is checked in #1, and Petitioner is checked in #2

                 

                I just dont know how to make this happen, any help would be great! thanks..