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

javascript using a constant Acrobat 5

mbush
Registered: Oct 13 2008
Posts: 6

I am trying to multiply a value from a form field by a constant and can not come up with the correct syntex. For example, I have a field for "quantity" and a field for "total" which is the "quantity" times a specific amount (the constant). I've tried the following:

var a = this.getField("pen wood qty");
var b = 40.00;
event.value = b.value * a.value;

which does not work. This is simple mathematics but I can't find out how to use make it work. Help would be appreciated, thanks!

My Product Information:
Acrobat Pro 5.x or older, Windows
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
You're close. The correct code would be:
var a = this.getField("pen wood qty");var b = 40.00;event.value = b * a.value;

Though this would be better:

(function() { // Get field value, as a numbervar a = +getField("pen wood qty").value; // Calculate value and set this field's value to the resultevent.value = 40 * a; })();

I put the code in the anonymous function that calls itself to limit the scope of any variables that are declared. This is a good practice to get in the habit of for code that you place in field events.

George