14 Replies Latest reply on Jan 27, 2014 5:25 AM by fezboy82

    Traffic light system

    Simonbx

      When selecting a number from a drop down menu is it possible to make a colour appear depending on what number is chosen. Like a traffic light system, you choose 1 and it comes up red, you choose 3 and it comes up green?

       

      Thank you for taking a look

      S

        • 1. Re: Traffic light system
          try67 MVP & Adobe Community Professional

          Yes, sure. You can use buttons with a graphic on them and then show/hide them, or you could use a button or text field and just change their fill color.

          • 2. Re: Traffic light system
            Simonbx Level 1

            Thank you for your response. I apologise for my ignorance but would it be possible for you to explain further. I created the form in Indesign exported it as a PDF (but not an interactive PDF) and then added drop down menus from there. If I create graphics in Indesign and give them a code is it possible to have them highlight when the certain number is selected? If so can you explain how?

             

            S

            • 3. Re: Traffic light system
              try67 MVP & Adobe Community Professional

              I don't think this is something you can do in ID, unless you define them as layers.

              However, it's not that complicated to do, but you need to explain a bit in more detail what exactly you want to have.

              • 4. Re: Traffic light system
                Simonbx Level 1

                Thank you for your quick response,

                 

                I have a form with various questions and from those questions are scores relating to each one. So the client has requested that if the customer only gives 1 out of 5 then this number 1 or a box/circle appears highlighted red. And then if they select the number 2 the number or a box/circle appears in the colour amber.

                 

                Doe this help explain a bit more?

                 

                S

                • 5. Re: Traffic light system
                  try67 MVP & Adobe Community Professional

                  Well, let's say your drop-down is called Score and you have a text field called ScoreColor.

                  You set your drop-down to commit the selected value immediately and add this code as its Validation script:

                   

                  this.getField("ScoreColor").value = event.value; // Copy the selected value to the text field

                  if (event.value=="1") {

                       this.getField("ScoreColor").fillColor = color.red;

                  } else if (event.value=="2") {

                       this.getField("ScoreColor").fillColor = color.yellow;

                  } else if (event.value=="3") {

                       this.getField("ScoreColor").fillColor = color.green;

                  }

                   

                  etc.

                  • 6. Re: Traffic light system
                    Simonbx Level 1

                    Wow thankyou. I shall try this and let you know how it goes.

                     

                    Many many thanks for your help.

                     

                    S

                    • 7. Re: Traffic light system
                      Simonbx Level 1

                      Hi again,

                       

                      This has worked perfectly. Thank you for your help with this, it is much appreciated.

                       

                      Simon

                      • 8. Re: Traffic light system
                        Simonbx Level 1

                        Hi I was wondering if you could help again with some Javascript

                         

                        Is it possible to create a weighted score? So for instance I want to have a score of 1 - 5 but then say numbers 3 and 4 are worth double or tripple. Is this possible?

                         

                        Thank you in advance.

                         

                        Simon

                        • 9. Re: Traffic light system
                          try67 MVP & Adobe Community Professional

                          You'll need to explain yourself a bit better...

                          • 10. Re: Traffic light system
                            fezboy82 Level 1

                            Hi, a question based around this topic. I am developing a risk assessment form and would also like to a traffic light indicator to appear depending on the risk. In my form I have added a text box that calculates a number based on the equation Risk = Severity x Likelihood

                             

                            Severity and Likelihood are rated from 1-5 meaning a range of numbers from 1-25. The risk is then calculated by where the total number sits in the range e.g. 1-7 = low risk (green), 8-15= medium risk (amber), 16-25 high risk (red)

                             

                            Thank you if anyone can provide an answer to this.

                             

                            Jon

                            • 11. Re: Traffic light system
                              try67 MVP & Adobe Community Professional

                              Well, you can use a slightly modified version of the script above. Something like this should do:

                               

                              var risk = Number(this.getField("Risk").value);

                              if (risk>=1 && risk<=7) {

                                   event.value = "Low Risk";

                                   event.target.fillColor = color.green;    

                              } else if (risk>=8 && risk<=15) {

                                   event.value = "Medium Risk";

                                   event.target.fillColor = color.yellow;

                              } else if (risk>=16) {

                                   event.value = "High Risk";

                                   event.target.fillColor = color.red;    

                              } else {

                                  event.value = "";

                                  event.target.fillColor = color.white;    

                              }

                               

                              This code should be used as the custom calculation script of the field where you want to display the "traffic light", and it assumes there's a field called "Risk" that contains the risk value (this field could be hidden).

                               

                              Edit: fixed code

                              • 12. Re: Traffic light system
                                fezboy82 Level 1

                                First off thank you for replying so quickly and your help

                                 

                                I have tried the script but can't get it to work. The form I have created so far allows the user to select drop down numbers from 1-5 for both Severity and then Likelihood. I have then put in a text field (named Risk1) that carrys out a product (x) calculation based on the numbers selected. I want the traffic light box to be displayed as a seperate field next to this.

                                 

                                I have been using a text field and alteretered the script you produced to account for risk1 field name. Is there a particular field type and set up I should use?

                                 

                                Sorry i'm such a pain with the questions, i'm a novice with putting together adobe forms.

                                • 13. Re: Traffic light system
                                  try67 MVP & Adobe Community Professional

                                  If you adjusted the field name in the code then that should be sufficient.

                                  What exactly goes wrong, though?

                                  Are there any error messages in the JS console?

                                  • 14. Re: Traffic light system
                                    fezboy82 Level 1

                                    I tried the code again and it worked perfectly this time. I can't thank you enough for your help on this.

                                     

                                    Jon