5 Replies Latest reply on Aug 29, 2017 2:39 AM by try67

    Get value of text field?

    calvins61590516

      Hoping someone can help me...

       

      I have a adobe form with a text input field alongside a checkbox. I want my javascript to basically do the following: check the number inserted by the user into the text field and then spawn template pages (amount equal to that of the number inserted in the text field).

       

      This is the code I have so far however it is not working, can someone tell me what I am doing wrong? (by the way, the code is inserted as a mouse down action on the checkbox). The name of the text field is "buildingsNumber" and the template name is "buildings".

       

      var bAmount = document.getElementById("buildingsNumber").value;

      var t = this.getTemplate("buildings");

      for (var i = 1; i <= bAmount; i++)

      t.spawn(i, true, false, XO);

        • 1. Re: Get value of text field?
          try67 MVP & Adobe Community Professional

          You're using JS code that was written for a web-page. It will not work in a PDF.

          Replace this part:

          document.getElementById

          With:

          this.getField

           

          Also, you've seemed to have copied the spawn command, but not in full. You're missing the first call to spawn, which is then saved in the XO variable. Your code as it stand will not work.

          • 2. Re: Get value of text field?
            calvins61590516 Level 1

            I have fixed the code to the below... but it is not inserting the pages that I want it to. Is this because of the spawn command not being used properly? I'm not 100% sure how to use the spawn command properly. It is not returning any errors when I run the code though. and if I change the for statement to the following: for (var i = 1; i <= 3; i++) , then it works and inserts 3 pages of the template that I want it to insert.

             

            var bAmount = this.getField("buildingsNumber");

            var t = this.getTemplate("buildings");

            for (var i = 1; i <= bAmount; i++)

            t.spawn(i, true, false);

            • 3. Re: Get value of text field?
              try67 MVP & Adobe Community Professional

              Change:

              var bAmount = this.getField("buildingsNumber");

              To:

              var bAmount = Number(this.getField("buildingsNumber").value);

              1 person found this helpful
              • 4. Re: Get value of text field?
                calvins61590516 Level 1

                ons step closer! This worked however now the pages only get inserted after the second time I click the checkbox.

                 

                So when the form is empty, i insert the number of pages into the buildingsNumber field and then i check the checkbox which should then spawn the pages... but it doesn't spawn the pages until I click the already checked checkbox again?

                • 5. Re: Get value of text field?
                  try67 MVP & Adobe Community Professional

                  Not sure I quite follow you, but you can try using the Mouse Up action of the check-box, not Mouse Down.

                  1 person found this helpful