5 Replies Latest reply on Jun 17, 2011 10:21 AM by George_Johnson

    Require certain fields depending on which radio button is checked

    KU#1N08

      I have a form with two parts. I've set up a radio button for Part 1 and Part 2. I'd like to require certain fields be completed if Part 1 is checked, and certain fields be completed if Part 2 is checked. I'm more than a newbie at Javascript. Can anyone help?

        • 1. Re: Require certain fields depending on which radio button is checked
          George_Johnson MVP & Adobe Community Professional

          When you say require, what do you mean exactly? Required to be complete before printing, saving, emailing, submitting, something else?

          • 2. Re: Require certain fields depending on which radio button is checked
            KU#1N08 Level 1

            I'd like them to be required prior to submitting. This is a report regarding real estate sold. Would it help if I sent you the form?

             

            Denise

            [signature deleted by host]

            • 3. Re: Require certain fields depending on which radio button is checked
              George_Johnson MVP & Adobe Community Professional

              Note that when you replay by email, it includes your info such as name, address, phone#, etc., which you may not want on a public web site. So it's better to return to the forum when replying. I will report this post and request that the info is removed.

               

              If you are really submitting to a web server and not simply emailing, then you can set the required property of each field that needs to be required. The submit action will not be allowed until all of the required fields are complete. This is a simple approach that really only works for text and signature fields, since check boxes, radio buttons, combo boxes, and list boxes normally always have a non-blank value. If you are emaiing using a submot form action with a mailto type URL, this will work also.

               

              A better approach that allows you to check these other field types and provide better feedback to the user is to loop through the fields that are required, check their value, and not allow the submit to take place if any fields are not completed correctly. For example, here's a code fragment that checks to see if a check box group has at least one item selected:

               

              // Get the value of the favorite color check box
              var v1 = getField("favorite_color").value;
              
              if (v1 === "Off") {
                  app.alert("Page 1, favorite color: You must make at least one selection.", 3)
              } else {
                  // Everything is OK, so go ahead with the submit
                  submitForm({cURL: "mailto:someone@example.com", cSubmitAs: "PDF"});
              }
              

               

              This code is just to get the idea across. It would obviously have to be expanded to account for multiple fields and fields of different types. I just did a small job for someone who needed something like this, so you can contact me offline if interested.

              • 4. Re: Require certain fields depending on which radio button is checked
                KU#1N08 Level 1

                Ooops! Obviously I'm a newbie at more than Javascript!

                 

                This is actually a pdf form that we make available to our members to submit sold information. I would be very interested in having you look at the form and give me a tip or two. Thanks!

                • 5. Re: Require certain fields depending on which radio button is checked
                  George_Johnson MVP & Adobe Community Professional

                  My email address is in my profile. Just click my name (in the forum) to see it.