使用Javascript在Acrobat中验证计算字段

时间:2014-02-25 18:50:32

标签: javascript validation acrobat

我正在创建一个计算加权费用的表单。表格基本上将分配百分比乘以预定义的年度百分比费用来计算加权平均费用。我试图找出确保表单用户使分配增加到100%的最佳方法。现在我的代码看起来像这样:

    var FeeTotal = (this.getField("dvisors Fee annum1").value 
    + this.getField("dvisors Feeannum2").value 
    + this.getField("dvisors Fee annum3").value 
    + this.getField("dvisors Fee annum4").value 
    + this.getField("dvisors Fee annum5").value 
    + this.getField("dvisors Fee annum6").value 
    + this.getField("dvisors Fee annum7").value 
    + this.getField("dvisors Fee annum8").value 
    + this.getField("dvisors Fee annum9").value 
    + this.getField("dvisors Fee annum10").value);

    var total = (this.getField("Manager%1").value 
    + this.getField("Manager%2").value 
    + this.getField("Manager%3").value 
    + this.getField("Manager%4").value 
    + this.getField("Manager%5").value 
    + this.getField("Manager%6").value 
    + this.getField("Manager%7").value 
    + this.getField("Manager%8").value 
    + this.getField("Manager%9").value 
    + this.getField("Manager%10").value);

    if (total=1) {
        event.value = FeeTotal;
        this.field.fontcolor("red");
    } else {
        event.value = FeeTotal;
        this.field.fontcolor("Black")
    }

这个想法是,如果分配百分比未添加到100%,则此脚本正在计算值的字段将具有红色文本。我不想使用app.alert,因为此表单的用户会经常更改分配百分比,并且常量警报会很麻烦。

谢谢!

1 个答案:

答案 0 :(得分:0)

根据此处讨论的内容,在Acrobat 7 pro中可以使用:

this.getField("thisfield").value = 
this.getField("field1").value +
this.getField("field2").value;

var total = (this.getField("thisfield").value);

var total2 = (this.getField("anothercalculatedtotalfield").value);

if (total2==(this.getField("thisfield").value)) {
    event.value = total;
    this.getField("thisfield").textColor = color.black;
} else {
    event.value = total;
    this.getField("thisfield").textColor = color.red;
}