首页 > 解决方案 > PDF JavaScript:将变量值插入表单字段

问题描述

我有一个带有 JavaScipt 的 PDF,所有最终用户都运行 Adob​​e Acrobat Pro DC。我已经成功地弄清楚如何让它用其他表单字段的值填充表单字段:

// Assuming FormFieldB has a value of "somewhere" and FormFieldA is a text box

this.getField("FormFieldA").value = "Fills a sentence and adds a string from " + this.getField("FormFieldB").value + " successfully.";

// This fills the box with "Fills a sentence and adds a string from somewhere successfully.

但是我想做的基本上是一样的,但我试图获取一个变量的值并将其添加到表单字段中。

var my_variable = "somewhere";

this.getField("FormFieldA").value = "Fills a sentence and adds a string from <How do I insert from my_variable> successfully";

// I want it do write the same example sentence as before

有任何想法吗?谢谢!

标签: javascriptvariablespdf

解决方案


只需连接字符串...

var my_variable = "somewhere";

this.getField("FormFieldA").value = "Fills a sentence and adds a string from "+my_variable+" successfully";

推荐阅读