8 Replies Latest reply on Jan 10, 2013 1:18 AM by boroclem

    Conditional Checkbox

    boroclem

      Hi All,

       

      I need help in javascript. I tried searching through the threads and trying out myself but still unable to do it.

      Please help.

       

      I got 5 questions with checkbox yes and no

      1.          cb Yes     cb No

      2.          cb Yes     cb No

      3.          cb Yes     cb No

      4.          cb Yes     cb No

      5.          cb Yes     cb No

       

      cb = checkbox

       

      At the end of the 5 questions, I got 2 checkbox with Pass or Fail

       

      cb Pass     cb Fail

       

      How can i javascript this form to reflect the pass or fail result.

      Conditions are either question ticked a Yes = Pass

      If all questions are ticked No = Fail.

       

      Thank you in advance for the help.

        • 1. Re: Conditional Checkbox
          try67 MVP & Adobe Community Professional

          You should do this with a button, as opposed to a "live" calclulation. Not only is it easier to implement but also if you use a live script it will be very obvious what caused the Fail response to trigger... The way to do it is to simply iterate over the check-boxes, checking their values. Are they named in a consistent way, like Q1, Q2, Q3, etc.?

          • 2. Re: Conditional Checkbox
            boroclem Level 1

            Thanks for your reply, I do not really understand what you mean by iterate over the check-boxes, checking their values?

             

            The checkbox i named them as yes1, yes2, yes3, no1, no2, no3 etc.

            The questions are different from each other.

            • 3. Re: Conditional Checkbox
              try67 MVP & Adobe Community Professional

              The check-boxes should have the same name, but different export values.

              Otherwise you could check both the Yes and No boxes on the same line, which

              is not what you want, I think... You should rename your boxes using the

              names I've specified. That would make writing the final script much easier.

              • 4. Re: Conditional Checkbox
                boroclem Level 1

                Ok, i think i got what you meant. But please correct me if i'm wrong.

                1) Replace the check-boxes to radio buttons, group the yes and no box together and name them the same.

                This way I can only click either the yes or no.

                 

                Am I right?

                 

                As for the different export values, could you elaborate me on that?

                 

                Thanks! (:

                • 5. Re: Conditional Checkbox
                  try67 MVP & Adobe Community Professional

                  It doesn't have to be radio-buttons, although it can be. Both radio-buttons

                  and check boxes will act the same way (pretty much) if they have the same

                  name but a different value, which you can set under Properties - Options

                  (it's called "Radio Button Choice" in some versions of Acrobat, or "Export

                  Value").

                  • 6. Re: Conditional Checkbox
                    boroclem Level 1

                    ok, i managed to do like what you suggested. Using checkbox, i named the each groups the same but different export value so they behaved the same how radio-buttons does.

                     

                    After this step, what is next? How can I condition it to result in a pass or fail context.

                    Thanks! (:

                    • 7. Re: Conditional Checkbox
                      try67 MVP & Adobe Community Professional

                      OK, so let's say you have 5 buttons named Q1 to Q5, and you have a text field that will show the result (called "Result"), and a button that generates the result. You place this code as the MouseUp action of the button:

                       

                      calcPass();

                      function calcPass() {

                           this.getField("Result").value = "";

                           var pass = false;

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

                                var a = this.getField("Q"+i).value;

                                // If any of the questions is not answered, abort

                                if (a=="Off") { return; }

                                // Otherwise, if the value is "Yes", the result will be "Pass"

                                pass = pass || (a=="Yes");

                           }

                           this.getField("Result").value = pass ? "PASS" : "FAIL";

                      }

                       

                      Thinking about it now, you can also do it without the button by placing this code as the custom calcluation script of "Result" and replace all instances of this.getField("Result").value with event.value .

                      • 8. Re: Conditional Checkbox
                        boroclem Level 1

                        I do not have a text field at the end of the 5 questions to show the result. But rather 2 checkbox that I would require to auto checked based on the pass/ fail result.

                        I have send the file i am working on to your email. Please help me take a look and advise me.

                         

                        Many Thanks. Appreciate it.