5 Replies Latest reply on Oct 22, 2013 2:23 PM by Rich_Henderson

    Javascript problem

    Rich_Henderson

      Hi,

       

      I have got six text fields (a - g) that if one of them gets filled, I want a seventh text field to be come a required field. So far I have gone about using:

       

                          var a = getField("description")

                          if (event.target.value == "") {a.required = false;} else {a.required = true;}

       

      and putting as a "mouse exit" event in fields a - g. However, I found that if you add text to field a, then enter and exit field b, the description field is no longer a required field.

       

      I think I need a more complex If statement that links all six fields together, but this is beyond me. Would it also be possible to put the Javascript in the description field? There are about 30 rows in my table, so any possible way to speed up the data entery would be really appricated (it isn't the most exciting task in the world now is it?)

       

      Cheers,

      Rich

        • 1. Re: Javascript problem
          try67 MVP & Adobe Community Professional

          Your code is not working correctly because you need to take all fields into consideration, and it can't be done from the description field.

          Basically you need to write a script that iterates over an array of the fields, checking all of them, and if none is filled-in set "description" as not required, otherwise as required. This script can be placed in a doc-level function and then applied to multiple fields using another script, that you would run the JS console.

          • 2. Re: Javascript problem
            Rich_Henderson Level 1

            How would I go about that then? Is this to complicated for a beginner like myself?

            • 3. Re: Javascript problem
              try67 MVP & Adobe Community Professional

              It's not super-complex, but not trivial either... You can look up some of the Acrobat JS tutorials online (I recommend those on AcrobatUsers.com) and see if you manage.

              • 4. Re: Javascript problem
                Rich_Henderson Level 1

                Excellent, I will give it a go. Thank you!!

                • 5. Re: Javascript problem
                  Rich_Henderson Level 1

                  I gave a script a go without using a doc-level script and it has worked. I though I would share it for anyone else who may want one:

                   

                  var a = this.getField("a.0");
                  var b = this.getField("b.0");
                  var c = this.getField("c.0");
                  var d = this.getField("d.0");
                  var e = this.getField("e.0");
                  var f = this.getField("f.0");
                  var g = this.getField("Decrib.0");
                  if (a.value == "" && b.value == "" && c.value == "" && d.value == "" && e.value == "" && f.value == ""){g.required = false;} else {g.required = true;}