14 Replies Latest reply on Mar 25, 2016 2:11 PM by mcelmurrygal

    Can You Change A Check Box Color When Checked?

    raypalmer Level 1

      Would like to know if there is a script available that would turn a "Yes" Check box to a green background "No" to red and "In Progress" to yellow?

       

      Yes_No_In_Progress.jpg

        • 1. Re: Can You Change A Check Box Color When Checked?
          try67 MVP & Adobe Community Professional

          It can be done, but it will change the fill color of all the fields in the group, not just the one that is ticked.

          What are the export values of each of these fields?

          • 2. Re: Can You Change A Check Box Color When Checked?
            raypalmer Level 1

            The export value is (1) for each. I'm also counting each row.

            • 3. Re: Can You Change A Check Box Color When Checked?
              raypalmer Level 1

              I would need them to be individual. So, if question one is yes then that yes would have the fill color of green and if question two was no then the fill would be red.

              • 4. Re: Can You Change A Check Box Color When Checked?
                try67 MVP & Adobe Community Professional

                That is not possible if they are a part of a group. If they're not then you'll have a different issue: It will be possible to check multiple fields, ie they will not be mutually exclusive.

                • 5. Re: Can You Change A Check Box Color When Checked?
                  Karl Heinz Kremer Adobe Community Professional

                  Yes, this can definitely be done. You mentioned that all your fields have an export value of one, that needs to be changed, otherwise you cannot distinguish between then, so in my following example, I am using "Yes', "No" and "InProcess". The three checkboxes would however have the same name, so that they are in the same group (this would make them behave similar to a radio button group).

                   

                  In  a group of fields (radio buttons or a checkbox group), every element of the group can be referenced as an individual "widget" and it's properties can be modified. Create a document level script named "processCBGroup" and use the following script:

                   

                  function processCBGroup(doc, ev)

                  {

                      var fYes = doc.getField(ev.target.name + ".0");

                      var fNo = doc.getField(ev.target.name + ".1");

                      var fInProcess = doc.getField(ev.target.name + ".2");

                      (ev.target.value == "Yes") ? fYes.fillColor = color.green : fYes.fillColor = color.transparent;

                      (ev.target.value == "No") ? fNo.fillColor = color.red : fNo.fillColor = color.transparent;

                      (ev.target.value == "InProcess") ? fInProcess.fillColor = color.yellow : fInProcess.fillColor = color.transparent;

                  }

                   

                  Now, call "processCBGroup(this, event);" from every button "Mouse Up" handler, and you should get what you want. However, based on your screenshot, it looks like you have the "Highlight Existing Fields" option turned on. This will mask the background color when the field is not the active field. Because of that, I always also change the stroke color, which will change the border around the field. That will be visible even with this feature turned on. I'll leave it up to you to modify the script so that it also changes the border color.

                  • 6. Re: Can You Change A Check Box Color When Checked?
                    mcelmurrygal Level 1

                    Karl Heinz Kremer

                     

                    Can you please help me and elaborate a little more creating a document level script? I see your instructions above and am trying to do the same thing (see screenshot below).

                     

                    I have a group of text (1 group per row, export values are: "YES", "NO", and "UNSURE"). I need the following colors/conditions and am unsure how to write the script please:

                    YES = GREEN when checked

                    NO = RED when checked

                    UNSURE = YELLOW when checked

                     

                    Also, this leads me to a couple questions:

                    1. How do I create the document level script in my form as you mention above

                    2. After I create the document level script, will this function automatically start to work? Or do I need to take any other action after the document script is created?

                     

                    Thank you in advance for any help you can provide!

                    Samantha

                     

                    Forgot my screen shot:

                    • 7. Re: Can You Change A Check Box Color When Checked?
                      gkaiseril MVP & Adobe Community Professional

                      One can create and edit document level scripts in Acrobat Professional. Without having the Professional version, one needs to use the JavaScript console to run a script that inserts the script at the document level or create an FDF file to insert the script at the document level.

                       

                      If you have a  one page PDF the script could also be created as a Page Open action.

                      • 8. Re: Can You Change A Check Box Color When Checked?
                        Karl Heinz Kremer Adobe Community Professional

                        Just creating the document level script will not make this work automatically. If you look at my reply, I said:

                        Now, call "processCBGroup(this, event);" from every button "Mouse Up" handler, and you should get what you want.

                        This is important, you will have to call the document level script from every radio button or checkbook in your group. You add document level scripts in Acrobat XI and DC via Tools>JavaScript>Document JavaScript. Just type a name, and then click on the "Add" button and enter your script (again, this requires Adobe Acrobat Pro - if you only have Standard, take a look here: Document Level Scripts With Acrobat Standard - KHKonsulting LLC)

                        • 9. Re: Can You Change A Check Box Color When Checked?
                          mcelmurrygal Level 1

                          Hi,

                           

                          Thank you for the clarification. Can you please provide the script I would use to create the document script when using my export values above (YES, NO, UNSURE)? I tried to modify your original one but I must be messing up somewhere because it's not working.

                           

                          Also, how do I "call the scripts" to my checkbox?

                           

                          I apologize if these are ignorant questions, as I'm learning this as I go.

                          • 10. Re: Can You Change A Check Box Color When Checked?
                            Karl Heinz Kremer Adobe Community Professional

                            Please provide the script you are using.

                            • 11. Re: Can You Change A Check Box Color When Checked?
                              mcelmurrygal Level 1

                              here's the script I put in the "Document level Javascript" by going to:          Advanced --> Document Processing --> Document JavaScripts --> Add

                               

                              function processCBGroup(doc, ev)

                               

                              {

                               

                                  var fYes = doc.getField(ev.target.name + ".0");

                               

                                  var fNo = doc.getField(ev.target.name + ".1");

                               

                                  var fUnsure = doc.getField(ev.target.name + ".2");

                               

                                  (ev.target.value == "Yes") ? fYes.fillColor = color.green : fYes.fillColor = color.transparent;

                               

                                  (ev.target.value == "No") ? fNo.fillColor = color.red : fNo.fillColor = color.transparent;

                               

                                  (ev.target.value == "Unsure") ? fUnsure.fillColor = color.yellow : fUnsure.fillColor = color.transparent;

                               

                              }


                              And then, when I correct the script above (after you help me with that part) - how do I "call this script" to my checkboxes?

                               

                              Thanks again for all your help!!

                              • 12. Re: Can You Change A Check Box Color When Checked?
                                Karl Heinz Kremer Adobe Community Professional

                                There is nothing wrong with your script. To finish this, just follow my instructions form above (quoted here again):

                                 

                                Now, call "processCBGroup(this, event);" from every button "Mouse Up" handler, and you should get what you want.
                                • 13. Re: Can You Change A Check Box Color When Checked?
                                  Karl Heinz Kremer Adobe Community Professional

                                  One more thing: In one of your replies you list your export values as "(YES, NO, UNSURE)", but in the script you are using "Yes", "No" and "Unsure" for the comparison. You will need to use the same capitalization in both places (export values and in your script).

                                   

                                  If you don't know how to attach a JavaScript to a button action: Bring up the button's properties dialog and go to the Actions tab:

                                   

                                  2016-03-25_16-45-58.png

                                   

                                  Then just use the one line script I quoted above.

                                  • 14. Re: Can You Change A Check Box Color When Checked?
                                    mcelmurrygal Level 1

                                    Thank you - everything worked.

                                     

                                    Thank you for all your help and patience