3 Replies Latest reply on Apr 28, 2013 10:23 PM by rollye830

    Clear fields when PDF page is spawned?

    adamss14 Level 1

      Hi all,

      I have a fillable PDF  form that has buttons at the top of every page for the user to  duplicate the page in case more information needs to be entered.  Here  is the javascript I'm using, courtesy of George Johnson:


      // Get a template object from an existing template
      var t = getTemplate("myTemplate");
      // Spawn the template on the page following this one, and rename the fields
      t.spawn({nPage: pageNum + 1, bRename: true, bOverlay: false});


      This  works great, except when the user has already filled out page 1, then  clicks the button to duplicate the page, the new page contains the  information already filled in by the user on page 1.  Is there a way to  clear the fields when the page is duplicated? I am using Adobe X Pro.   Thank you!!!

        • 1. Re: Clear fields when PDF page is spawned?
          adamss14 Level 1

          Update: I found this code:



          var iPage = 0; // This is your page number, it is 0-based, so page 1 is 0




          var sFields = new Array();// array of fields names that are found




          for(var x=0;x<numFields;x++)




          {var pg = getField(getNthFieldName(x)).page;if((typeof pg == 'number' && pg == iPage) || (typeof pg != 'number' && pg.indexOf(iPage) > -1))sFields[sFields.length] = getNthFieldName(x);}




          if(sFields.length > 0)resetForm(sFields);


          This code does work, but instead of blanking out the NEW page, it blanks out the original one. Preferably, the original page would retain the information and the new form would be cleared.  I changed var iPage = 0 to var iPage = pageNum +1 and that seems to blank out the spawned page.  Even when I press the button on the spawned page, the second spawned page is cleared.


          I know very little about javascript so if anyone sees any problems with this code or the change I made, I'd appreciate if you give me a shout.  Otherwise I guess I resolved this on my own. Thanks!

          • 2. Re: Clear fields when PDF page is spawned?
            gkaiseril MVP & Adobe Community Professional

            PDF text form fields with the same name share most of their properties including their values. All of your fields need to be uniquely named whether on a form page or template page.


            Do not use a form page as a template.


            A Lesson in Templates for Adobe Acrobat by Dave Wright


            I make the form, then make that form as a template, spawn a page from that template, hide the template, rename the fields on the form to start with "P0." and not "P1.". This is quite easy when you use the Nav panel for the fields.


            If I want a field on the spawned page to have a value from the first page of the form, I rename that field on the form to the same field name as the template. You could add code the JS that spawns the new page to copy the value of the field from the first page to the new page.


            All of your actions using any fields on the spawned pages will require custom JavaScript coding, since you are going to have to adjust the field names for the prefix of the page number and the name of the template that spawned that page. This prefix could be computed from the form field in which the script is located by using the 'event.target.name' to get the focused field and then splitting the field name at the ".".

            • 3. Re: Clear fields when PDF page is spawned?
              rollye830 Level 1

              So simple. Works perfect. Thanks!