简体   繁体   中英

Add one day to User-Input Day using Javascript in a PDF

I am needing to generate a field with the next date after a user inputs one date in a PDF using Javascript. Here is my code so far:

var numDaysToAdd = 1;
var inputDateString = getElementById("Date.1").value;
var resultDate = stringToDate(inputDateString);
resultDate.setDate( resultDate.getDate()+numDaysToAdd );
var result = dateToString( resultDate );
event.value = result;

Using this code, I get no return in the field. If I input "11.23.15" instead of the get Element for inputDateString, I get the result "12.11.16". So I have two issues - it doesn't seem to be pulling the value from Date.1, and when I add one day, it adds a whole lot more than a day. Thanks for the help.

You may be aware that Acrobat JavaScript (which is used within PDF) has a completely different object model than webbrowser JavaScript. It is therefore highly recommended to get the Acrobat JavaScript documentation, which is part of the Acrobat SDK documentation, downloadable from the developer section of the Adobe website.

That said, you would add the following to the Calculate event of the field where the result should appear (we assume that the date in the field "Date.1" has the format "MM/DD/YYYY" ):

var numDaysToAdd = 1 ;
var fromDate = util.scand("mm/dd/yyyy", this.getField("Date.1").value) ;
var toDate = fromDate ;
toDate.setDate(fromDate.getDate() + numDaysToAdd) ;
event.value = util.printd("mm/dd/yyyy", toDate) ;

And that should do it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM