Acrobat XI Pro: checking status of a checkbox to affect calculation

梦想与她 提交于 2019-12-13 06:53:05

问题


I'm trying to add calculations to a form someone else created, and I'm a little stuck on the JS. One set of fields has two possible calculations depending on whether the associated checkbox is Checked or Unchecked. How do I a) check to see the status of the checkbox, and b) have that affect the calculation?

I know that for part b I will use some kind of if-else statement, and I've already got something coded that should work, but part a has me totally confused. It's been a while since I last did any coding, so my skills and knowledge are a bit rusty. Here's the code I have so far:

//check bonus = stat bonus + applicable proficiency bonus

var profUse = this.getField("SavStrProf").value;
var stat = Number(this.getField("SavStrVal").value);
var profVal = Number(this.getField("Proficiency Bonus").value);
var check = Number('-2');

if (profUse == checked){
    check = stat + profVal;
}
else{
    check = stat;
}

event.value = check;

If it helps to have the PDF form I'm working with, you should be able to find it here: http://www.enworld.org/forum/rpgdownloads.php?do=download&downloadid=1089


回答1:


It might be useful to have a closer look at the Acrobat Javascript documentation, which is part of the Acrobat SDK, downloadable from the Adobe website.

A checkbox has a return value; that is the field value when it is checked. When it is not checked, its value is always "Off".

The simplest way to test for a (single) checkbox would look like this:

if (this.getField("myCheckBox").value != "Off") { 
   // the box is checked 
   // do what should be done when the box is checked 
} else { 
   // the box is not checked 
   // do what should be done when the box is not checked 
}

In many cases, a smart choice of the return value of the check box can simplify calculations.



来源:https://stackoverflow.com/questions/27471285/acrobat-xi-pro-checking-status-of-a-checkbox-to-affect-calculation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!