I'm a complete novice with javascript and programming in general, so I need help with something I'm trying to accomplish in Acrobat. I've created an expense form with some simple calculations. What's giving me trouble is how certain results are being displayed. Two of the results deal with a cash advance and how much money is due to the employee, or how much is owed to the company by the employee (fields: cashdue and cashowed). I used a subtraction javascript to calculate the results:
cashdue
Var a=this.getField("cashsubtotal").value;
Var b=this.getField("cashadvance").value;
event.value=a-b
cashowed
Var a=this.getField("cashsubtotal").value;
Var b=this.getField("cashadvance").value;
event.value=b-a
The problem is, I'm getting the same result in each field (one positive, the other negative), depending on the data entered. What I want to do is write an if/then script that will make the result show as $0.00 if it is a negative number. If someone could give me a hand I would appreciate it. I found the subtraction script on this forum, and reading articles on if statements has only made me more confused.
Thanks
// cashdue
var a=this.getField("cashsubtotal").value;
var b=this.getField("cashadvance").value;
event.value=a-b // compute due
if (event.value < 0) event.value = 0; // if negative set result to zero// cashowed
var a=this.getField("cashsubtotal").value;
var b=this.getField("cashadvance").value;
// set event value to b-a if "b - a > 0" : else set it to 0
event.value = b - a > 0? b-a : 0;Note: original used 'Var' instead of 'var'.
George Kaiser