10 Replies Latest reply on May 12, 2014 6:33 AM by top_jimmy44

    Change in radio button clears out other radio button selections

    top_jimmy44

      I have a PDF form where a user can select one of three options (radio button).

       

      Once they make that selection, an associated radio button also needs selected, plus two check boxes are included in that section.  I want the second set of radio buttons and the two check boxes cleared when the value of the first radio selection is changed.  Is that possible?

       

      Here's the detail:

       

      First, the user selects if the student is promoted, retained or other.

       

      If they select Promoted, they then need to choose the grade the student was promoted to in another radio button group (1st grade to 7th grade).  They also have the ability to mark two independent checkboxes related to promotion to next grade, such as "with an IEP" or "other".  The Other checkbox also has a textbox to specify why they selected other.

       

      If they select retained, they then need to choose the grade the student was retained in (K-6th grade).  They also have two independent checkboxes related to retention in that grade, such as "referred for testing" and "other".  Again, other has a specify text box.

       

      If they select Other, there is a please specify text box.

       

      What I want to happen is for the form to correct itself by clearing fields when incorrect selections are made.  For example, if someone selects Promoted and then selects grade 2, plus fills in one or more of the promotion checkboxes, but realizes they should have selected Retained, the selection of retained would clear out all associated Promotion fields.

       

      Is this possible?

        • 1. Re: Change in radio button clears out other radio button selections
          gkaiseril MVP & Adobe Community Professional

          You can use the "resetForm" method to clear the field or select the form fields to be clear fields. Since one can not uncheck a radio button you could use the mouse up action to clear the other fields either by using JavaScript or selecting the clear form action and the fields to clear.

          • 2. Re: Change in radio button clears out other radio button selections
            top_jimmy44 Level 1

            I found a javascript on the forums that could be used to clear check boxes using the script on the mouse up.  What I ended up trying to do was switching all of the radio buttons to check boxes with the same name, but different export values, applied the same type of javascript, but with my own field names.  It didn't work though.  Is there something that has to be done to save the form so a javascript will run?

             

            This is the javascript I used.  Only thing I'm not sure about is how to reference a check box if multiple check boxes have the same name.  Acrobat gives them #'s, so I used that.  Is that wrong?

             

            // Document-level function 

                function cbControl() { 

                 

                    // Get a reference to each check box 

                    var f1 = getField("PromotionRetentionOther#0"); 

                    var f2 = getField("PromotionRetentionOther#1"); 

                    var f3 = getField("PromotionRetentionOther#2");

                var f4 = getField("PromotedGrade#0");

                var f5 = getField("PromotedGrade#1");

                var f6 = getField("PromotedGrade#2");

                var f7 = getField("PromotedGrade#3");

                var f8 = getField("PromotedGrade#4");

                var f9 = getField("PromotedGrade#5");

                var f10 = getField("PromotedGrade#6");

                var f11 = getField("Promoted with IEP");

                var f12 = getField("PromotedOther");

                var f13 = getField("PromotionOtherSpecify");

                var f14 = getField("RetainedGrade#0");

                var f15 = getField("RetainedGrade#1");

                var f16 = getField("RetainedGrade#2");

                var f17 = getField("RetainedGrade#3");

                var f18 = getField("RetainedGrade#4");

                var f19 = getField("RetainedGrade#5");

                var f20 = getField("RetainedGrade#6");

                var f21 = getField("Retained referred for testing");

                var f22 = getField("Retained Other");

                var f23 = getField("Retained Other Specify");

                var f24 = getField("Promotion_Retention other Specify"); 

                 

             

                 

                    // Uncheck Retained or Other values if Promotion is checked

                    if (event.target === f1) { 

                           f2.value = "Off"; 

                           f3.value = "Off";

                    f14.value = "Off";

                    f15.value = "Off";

                    f16.value = "Off";

                    f17.value = "Off";

                    f18.value = "Off";

                    f19.value = "Off";

                    f20.value = "Off";

                    f21.value = "Off";

                    f22.value = "Off";

                    f23.value = "Off";

                    f24.value = "Off";   

                         

                    }

             

                // Uncheck Promotion or Other values if Retained is checked

                    if (event.target === f2) { 

                           f1.value = "Off"; 

                           f3.value = "Off";

                    f4.value = "Off";

                    f5.value = "Off";

                    f6.value = "Off";

                    f7.value = "Off";

                    f8.value = "Off";

                    f9.value = "Off";

                    f10.value = "Off";

                    f11.value = "Off";

                    f12.value = "Off";

                    f13.value = "Off";

                    f24.value = "Off";

                }

             

                // Uncheck Promotion or Other values if Retained is checked

                    if (event.target === f3) { 

                           f1.value = "Off"; 

                           f2.value = "Off";

                    f4.value = "Off";

                    f5.value = "Off";

                    f6.value = "Off";

                    f7.value = "Off";

                    f8.value = "Off";

                    f9.value = "Off";

                    f10.value = "Off";

                    f11.value = "Off";

                    f12.value = "Off";

                    f13.value = "Off";

                    f14.value = "Off";

                    f15.value = "Off";

                    f16.value = "Off";

                    f17.value = "Off";

                    f18.value = "Off";

                    f19.value = "Off";

                    f20.value = "Off";

                    f21.value = "Off";

                    f22.value = "Off";

                    f23.value = "Off";

                   

                }             

                } 

            • 3. Re: Change in radio button clears out other radio button selections
              try67 MVP & Adobe Community Professional

              If you have multiple copies of the same field you only need to access them once, as they all share the same value property.

              • 4. Re: Change in radio button clears out other radio button selections
                top_jimmy44 Level 1

                So how in the code would I determine which check boxes to clear out if I only reference it once?  Each section of the code clears a different group of check boxes.

                • 5. Re: Change in radio button clears out other radio button selections
                  try67 MVP & Adobe Community Professional

                  They're a group. By setting the group's value to "Off" you'll clear all of them at the same time.

                  • 6. Re: Change in radio button clears out other radio button selections
                    top_jimmy44 Level 1

                    I apologize.  This is the first time I have ever used Javascript programming.  How do I set the group's value to Off?

                    • 7. Re: Change in radio button clears out other radio button selections
                      try67 MVP & Adobe Community Professional

                      You're already doing it... For example:

                       

                      this.getField("PromotionRetentionOther").value = "Off";

                      • 8. Re: Change in radio button clears out other radio button selections
                        top_jimmy44 Level 1

                        OK.  So if I am already doing it in the code, what is causing that code to not work?  I don't understand what I am doing wrong.

                        • 9. Re: Change in radio button clears out other radio button selections
                          try67 MVP & Adobe Community Professional

                          You're not doing it correctly at the moment. You're trying to access "PromotionRetentionOther#0", which is not a correct field name.

                          • 10. Re: Change in radio button clears out other radio button selections
                            top_jimmy44 Level 1

                            OK.  I understand now.  I changed it to this and it worked.  Thanks for your help.

                             

                            // Document-level function 

                                function cbControl() { 

                                 

                                    // Get a reference to each check box 

                                    var f1 = getField("PromotionRetentionOther"); 

                                var f2 = getField("PromotedGrade");

                                var f3 = getField("Promoted with IEP");

                                var f4 = getField("PromotedOther");

                                var f5 = getField("PromotionOtherSpecify");

                                var f6 = getField("RetainedGrade");

                                var f7 = getField("Retained referred for testing");

                                var f8 = getField("Retained Other");

                                var f9 = getField("Retained Other Specify");

                                var f10 = getField("Promotion_Retention other Specify"); 

                                 

                             

                                 

                                    // Uncheck all values if PromotionRetentionOther is checked

                                    if (event.target === f1) { 

                                           f2.value = "Off"; 

                                           f3.value = "Off";

                                    f4.value = "Off";

                                    f5.value = "Off";

                                    f6.value = "Off";

                                    f7.value = "Off";

                                    f8.value = "Off";

                                    f9.value = "Off";

                                    f10.value = "Off";

                                   

                                    }

                             

                                }