简体   繁体   English

使用Acrobat X Pro,需要javascript帮助

[英]Using Acrobat X Pro, need javascript help

I have a form that I have created in Acrobat X Pro. 我有一个我在Acrobat X Pro中创建的表单。 The form has several fields on it that a user would enter data in to get the cost of a photo session. 表单上有几个字段,用户可以输入数据以获得照片会话的费用。

Fields: Text1 (has a default value of $25. User cannot change this) 字段:Text1(默认值为$ 25。用户无法更改此内容)
Text2 (has a default value of $15. Use cannot change this) Text2(默认值为$ 15.使用无法更改此项)
Text3 (is a numeric fillable field by the user. Values to be entered are from 1 - 5) Text3(用户是一个数字可填写字段。要输入的值是1 - 5)
Text4 (is a numeric fillable field by the user. Values to be entered are 1 - infinity) Text4(用户是一个数字可填写字段。要输入的值是1 - 无穷大)
TotalCost (calculates the total of either Text1 x Text3 OR Text2 x Text4) TotalCost(计算Text1 x Text3或Text2 x Text4的总和)

I need to write a javascript calculation for the TotalCost field. 我需要为TotalCost字段编写一个javascript计算。 In Excel, i can write the formula like this: if(b9<>"",b6*b9,if(b10<>"",b7*b10,0) 在Excel中,我可以这样编写公式:if(b9 <>“”,b6 * b9,if(b10 <>“”,b7 * b10,0)

However, I am not sure how to write it in Javascript for the PDF form. 但是,我不知道如何在Javascript中为PDF表单编写它。 I am thinking it is like: 我在想它是这样的:

var a = this.getField("Text1")
var b = this.getField("Text2")
var c = this.getField("Text3")
var d = this.getField("Text4")

total.cost = if(getField("text3").value <>"", getField("text1").value*getField("text3").value,if(getField("text4").value <>"",getField("text2").value*getField("text4").value,0))

am i correct or totally off the mark? 我是正确还是完全不合适?

Close. 关。 Here: 这里:

var t1 = this.getField("Text1");
var t2 = this.getField("Text2");
var t3 = this.getField("Text3");
var t4 = this.getField("Text4");

var total = 0;
if (t3.value != "") {
  total = t1.value * t3.value;
} else if (t4.value != "") {
  total = t2.value * t4.value;
}

this.getField("TotalCost").value = total;

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

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