6 Replies Latest reply on Feb 19, 2016 9:54 AM by Onsightclimb

    Checking last checkbox value

    Onsightclimb

      I have a problem and need some help, please.

      I have 40 groups of checkboxes,in each group is 7 checkboxes , every group has unique name and value.

      User can check random number of groups, in range betwen 1 - 40. Here is my problem. Can I use javascript to get value of LAST checked group?

      If user check for example 11 groups in row...i need to get value of eleventh group. Am I making any sence? Is this possible?

       

      TNX for any help.

        • 1. Re: Checking last checkbox value
          gkaiseril MVP & Adobe Community Professional

          JavaScript only knows fields by name. So you need to figure out how to name your fields in such a manner that arranges them in row order.

           

          I would look at using hierarchical field names with the same parent name and each child goup is an ascenting number. One could then check each group and track the last group that does not have a value of "Off".

          • 2. Re: Checking last checkbox value
            Onsightclimb Level 1

            I have diferent names of groups. First is "r1", second "r2"...and so on all way to "r40". I dont know how to put together script, that will track the last group with value, that is not "OFF"? Can you show me?

            • 3. Re: Checking last checkbox value
              George_Johnson MVP & Adobe Community Professional

              One way would be to use a script that's called in the Mouse Up event of each check box that sets the value of a (hidden) text field to the value of the check box. It could be something like:

               

              // Function in a document-level script

              function setLastVal() {

               

                  // Get the value of the check box that triggered this function

                  var val = event.target.value;

               

                  // Set the value of the text field to this value

                  if (val !== "Off") {

                      getField("LAST_CB_VAL").value = val;

                  }

               

              }

               

               

              where "LAST_CB_VAL" is the name of the text field that holds the most recently selected check box value. To retrieve it, just get the value of this text field. You would have to call this function in the Mouse Up event of each check box like this:

               

              // Mouse Up script of checkbox

              setLastVal();

               

               

              It would be tedious to manually do this, but you can use the following script to automate it:

               

              // Set the Mouse Up script for all of the check boxes

              var sJS = "getField(\"LAST_CB_VAL\").value = val;";

              for (var i = 1; i <= 40; i += 1) {

                   getField("r" + i).setAction("MouseUp", sJS);

              }

               

               

              This can either be the Mouse Up script of a temporary button or can be entered, selected, and run in the interactive JavaScript console (Ctrl+J).

              • 4. Re: Checking last checkbox value
                Onsightclimb Level 1

                I will try this and let you know. Thank you very much.

                • 5. Re: Checking last checkbox value
                  George_Johnson MVP & Adobe Community Professional

                  I made a mistake in that last script. It should be:

                   

                  // Set the Mouse Up script for all of the check boxes

                  var sJS = "setLastVal();";

                  for (var i = 1; i <= 40; i += 1) {

                       getField("r" + i).setAction("MouseUp", sJS);

                  }

                  • 6. Re: Checking last checkbox value
                    Onsightclimb Level 1

                    Dear George

                    Script works perfect. I have just one problem...this script is for active check boxes. If I manualy check, then the value of last checked box is showing in textfield. Problem is, that in my document I have 5 pages. On first page I have group of 7 check boxes. On 5 page I have 40 groups, every group has also 7 check boxes. On top of every of this 40 groups I have button. Pressing on button copy current value of check boxes on first page and display that value in group on 5 page. Example:

                    User can select one of 7 check boxes (every box has unique value), all boxes has same name. When he select one of this boxes, he can go on page 5, where are 40 groups with also 7 check boxes (same system as above). He can push button on top of first group and value from page 1 is copied to check boxes on 5 page. Next day he can do the same thing with next group on page 5...and so on.

                    Problem is, that boxes on page 5 are read only.

                    So...is that code that you send possible to use on pasive (read only) check boxes? I try with button, that trigger this..but doesnt work.

                    Is there a way to get this all done with button, who will trigger action?