简体   繁体   English

使用PDF中的Javascript将一天添加到用户输入日

[英]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. 用户需要使用Javascript在PDF中输入一个日期后,我需要使用下一个日期生成一个字段。 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". 如果我输入“ 11.23.15”而不是inputDateString的get元素,则会得到结果“ 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. 因此,我有两个问题-它似乎并没有从Date.1中提取值,而当我添加一天时,它增加的时间远远超过一天。 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. 您可能会意识到,Acrobat JavaScript(在PDF中使用)具有与Web浏览器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. 因此,强烈建议您获取Acrobat JavaScript文档,该文档是Acrobat SDK文档的一部分,可从Adobe网站的开发人员部分下载。

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" ): 也就是说,您可以将以下内容添加到应显示结果的字段的Calculate事件中(我们假设字段“ Date.1”中的日期格式为"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. 那应该做到的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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