7 Replies Latest reply on Jul 25, 2009 1:26 AM by try67

    How can I find the status of a checkbox?

    Papaturro

      I am writing an invoice which involve Parts and Labor for an auto shop.  A check box precedes each line.  If the checkbox is checked, then the line is for a part, which I will use to add parts and labor separately for tax and information purposes.

       

      Question:  Using Acrobat Professional 8, what Java code would check whether a checkbox named CB1 is checked or not?.

        • 1. Re: How can I find the status of a checkbox?
          try67 MVP & Adobe Community Professional

          This will get you the value:

          this.getField("CB1").value

           

          The value itself depends on how you set it up. It can be "Off"/"On", "Yes"/"No", or something like that.

          • 2. Re: How can I find the status of a checkbox?
            Papaturro Level 1

            Thanks you so much.  The answer was obvious (that is, after you said it).  So, likewise, I would guess.  Let's say that I established the return value as "Yes" when I created the check box.  That means that I can switch it off if I set the value getField("CB1").value=="No".

            • 3. Re: How can I find the status of a checkbox?
              try67 MVP & Adobe Community Professional

              No neccsarily. I think the default value when the button is not checked is

              "Off".

              But that might depend on your version and settings.

              • 4. Re: How can I find the status of a checkbox?
                Papaturro Level 1

                Thanks for your valuable time.  I am stuck with this item.  Please, consider the following code:

                 

                var strCheckBox;
                var flgCBStatus;
                var strItemLine;
                var dblTotalParts = 0;
                var dblLineValue;

                 

                this.getField("AllParts").value = 0;

                var i = 0;
                while( i < 16 )
                {
                strCheckBox = "CB" + i;  //that will result in strCheckBox = "CB0" trough CB15
                strItemLine = "LT" + i;      // Same with this other field.  But this seems to be working

                 

                dblLineValue = this.getField(strItemLine).value;
                flgCBStatus = this.getField(strCheckBox).value;  // Message I get "this.getField(strCheckBox) has no properties"

                                                                                    

                if(dblLineValue > 0)
                {
                //  if(flgCBStatus == "Yes")

                             dblTotalParts = dblTotalParts + dblLineValue;
                }
                i++;
                }

                if(dblTotalParts > 0)
                      this.getField("AllParts").value = dblTotalParts;

                // End of procedure

                 

                I defined the CheckBox (which are labeled CB0 trough CB15 in the form) to return the value "Yes".

                 

                I need the loop to find the status of every line in the form.  I would appreciate any comment on it.  Also, I changed the CB so it would return "ON" instead of Yes as originally set up,but it does not make any difference.

                 

                Thanks in advance.

                • 5. Re: How can I find the status of a checkbox?
                  try67 MVP & Adobe Community Professional

                  You need to check your field names. It seems there's a problem there.

                  Add a console.println line to debug which field causes the problem.

                  In addition, this line (probably) won't work:

                  if(dblLineValue > 0)

                   

                  You need to convert the field's value to a proper number (it's usually a

                  String) in order to compare it to 0 in that way. You can multiple if by 1,

                  or use the new Number() function to do that.

                  • 6. Re: How can I find the status of a checkbox?
                    Papaturro Level 1

                    I want to cheerfully thank you for your support.  You gave me excelent leads that helped me to get the answer.

                     

                    The check box, I found, can be assigned a return value.  In my case it was "Yes".  If you don't the default return is "On" and, in any case if it is not checked, the return value is always "Off".

                     

                    You were right also when you sent me to review the names of the check boxes.  It turned out that the last two check boxes were name CB14, instead of CB14 and CB15.  So, when the loop reached the last one it trigger an error since it was name CB14 instead of CB15.  Simple bug but powerful enough to keep me up to 3 o'clock in the morning.

                     

                    Lastly.  The line that you think it probably won't work because it may be returning a string as oppossed to a numeral value, actually works, because the field was formatted as a number and this is what it returns.

                     

                    I decided to inform you about the whole thing, basically because I felt that is good to have feed back.  You definetively helped me.  Secondly, I wanted to share my small finding in case you can use it.

                    • 7. Re: How can I find the status of a checkbox?
                      try67 MVP & Adobe Community Professional

                      Thanks, and I'm glad to hear you were able to solve it...