Calculator - Adobe 12001196 - Acrobat - Mac Manual

Javascript
Hide thumbs Also See for 12001196 - Acrobat - Mac:
Table of Contents

Advertisement

Acrobat JavaScript Debugger
3
Exercise: Calculator
– Step Into
– Step Out
– Quit

Calculator

Calc.pdf uses document-level and form field-level scripts to create the behavior of a
simple calculator. The key pad consists of numeric and function keys, the period (.), the
equals sign (=), as well as Cancel and Cancel Entry keys.
How the Calculator Displays Output
Calc.pdf uses the Acrobat
that the user enters and the results of evaluating expressions to the calculator display
window. The calculator display window is the text field Display. In this statement,
getField() binds the variable display to this field:
var display = this.getField("Display");
Each numeric key is a button field with this Mouse Up action whose return value is assigned
to the calculator display window:
display.value = digit_button(n);
For example, when the user presses the "Seven" button, this assigns the value returned by
digit_button(7) to the calculator window.
Calc.pdf uses a similar mechanism to display the strings representing arithmetic
operations to the Func text field. In this statement, getField() binds the variable
display to this field:
var func = this.getField("Func");
Here is the Mouse Up action for the division (/) key:
func_button("DIV");
The action passes the string "DIV" to the func_button() function. The parameter is
assigned the name req_func, so when func_button() is executed,
req_func = "DIV"
Later in the function, this statement is encountered:
func.value = req_func
Because getField() has bound the func variable to the "Func" field, this statement
displays the string "DIV" in the field.
Adjusting For 2-Digit Values
To adjust for values entered that are greater than or equal to 10, the calculator multiplies
the current value by 10. For values less then 1, it multiplies the divisor 10. Say, for example,
the user enters the values 2 and 4 consecutively. The code multiplies the 2 by 10 and adds 4
to the result. The point button Mouse Up action updates the divisor to 10 if it is 1. This
48
Doc Object
method getField() to display the values of keys
Acrobat JavaScript Scripting Guide

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

Acrobat 6.0

Table of Contents