These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Display blank when there is no number inputs.

yesjcho
Registered: Aug 5 2010
Posts: 4

i have 3 fields that need to subtract.
i tried this script. it works well, but i want "balance" field to display a value even if the value comes out ZERO.
AND the default value of balance field should be the blank. That means if there is no inputs(blank) in those three fields, 'balance' field should be the blank or hidden.
thank you!

var j = this.getField("TCA");
var i = this.getField("PPA");
var l = this.getField("SUMMARY");
event.value = j.value - i.value - l.value ;

var v = this.getField("balance");
var theValue = v.value;
if (isNaN(theValue) || (theValue < 0.005)){
v.display = display.hidden;
}
else{
v.display = display.visible;
}

My Product Information:
Acrobat Pro 9.3.1, Windows
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
First, I would get rid of all unnecessary code. You do not need to try every possible way to access a field.

Are any of the input fields the result of a calculation?

What are the formats of all of the fields for this calculation?

What action do you want taken if the result is negative?

I prefer not to use single letter variables because it makes the scripts hard to read and some of the system functions use single letter variables that could be confused with user single letter variables.

A possible solution:
var nTCA = this.getField("TCA").valueAsString;var nPPA = this.getField("PPA").valueAsStringvar nSummary = this.getField("SUMMARY").valueAsString;event.value = ''; // null out the event value var nDifference = 0;if(nTCA != '' & nPPA != '' & nSummary != '') {// if inputs not null values compute the differencenDifference  = Number(nTCA) - Number(nPPA) - Number(nSummary) ;}  if( Math.abs(nDifference) > 0.005 ) {// if the result is > 0.005 or less then -0.005 display the resultevent.value = nDifference;}

George Kaiser

yesjcho
Registered: Aug 5 2010
Posts: 4
thank you so much!
this looks great!
but doesn't display when the result is zero.
i wanna make it display even if the result is zero.
how i do that?