I have a form that I have created in Acrobat X Pro. The form has seve开发者_JAVA技巧ral 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)
Text2 (has a default value of $15. Use cannot change this) Text3 (is a numeric fillable field by the user. Values to be entered are from 1 - 5) Text4 (is a numeric fillable field by the user. Values to be entered are 1 - infinity) TotalCost (calculates the total of either Text1 x Text3 OR Text2 x Text4)I need to write a javascript calculation for the TotalCost field. In Excel, i can write the formula like this: if(b9<>"",b6*b9,if(b10<>"",b7*b10,0)
However, I am not sure how to write it in Javascript for the PDF form. 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;
精彩评论