4 Replies Latest reply on Jul 31, 2013 3:24 PM by luog1

    Javascript button fields


      Hello, I am using Acrobat X Pro on windows for making forms. I have a form set up that auto fills the current date on certain fields upon page open. I also have a button that changes the date to the next day when clicked. I am wondering if there is a javascript code that can make it so that clicking the same button twice will update the field 2 days from the current day, and clicking it three times for 3 days from today, etc.


      I googled extensively but could not find anything about making multiclickable button fields.

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

          It's exactly the same logic... Take the current value, convert to a Date

          object, add 24 hours (in ms), and print it back to the field.

          1 person found this helpful
          • 2. Re: Javascript button fields
            luog1 Level 1

            Sorry, I forgot to mention I did't know anything about writing javascript. The code I'm using now for the button is

            var f = new Date() ;

            this.getField("date").value = util.printd("m/d/yy", new Date(f.getFullYear(),f.getMonth(),f.getDate()+1)) ;


            does something need to be added, or would i need to replace the entire code?

            • 3. Re: Javascript button fields
              gkaiseril MVP & Adobe Community Professional

              Your script populates the field with the system date plus 1 day. This is different from taking a date field value and adding one day.


              To accomplish what you want to do, you must first obtain the value of the text field.


              What do you want to do if that field is blank?


              var cDate = this.getField("date").value;

              // test for empty field value;

              if(cDate == "") {

              // empty field, then set to system date;

              this.getField("date").value = util.printd("m/d/yy", new Date());

              // refreash value;

              cDate = this.getField("date").value;

              } // end empty field value

              // covert the date value to a date object;

              var oDate = util.scand("m/d/yy", cDate);

              // set  date to date plus 1 day;

              oDate.setDate(oDate.getDate() + 1);

              this.getField("date").value = util.printd("m/d/yy", oDate);

              • 4. Re: Javascript button fields
                luog1 Level 1

                The field will always be filled since I have the document fill the date on page open. Thank you. I just added the script to the button and it works exactly as I wanted.