Use <meta name="openaction"> and field.setAction(); to define form actions corresponding to form events by JavaScript. It is available in AH Formatter V6.4 or later.
-
A <meta name="openaction" content="#JavaScript=..."> in <head> runs a script on PDF open.
-
Inside the script, get field by its HTML 'name' attribute: var myField = this.getField('fieldName');
-
Assign actions: myField.setAction('EventName', 'JavaScript code for event'); (e.g., 'MouseUp').
This PDF form is defined as follows:
<form>
<div class="form-container">
Push Button field:
<input type="button" name="chkButton" value="chk button"
style="width: 10em; height: 1.2em;
background-color: #eee; border: 2px silver outset;
-ah-field-type: button; -ah-field-button-layout: caption;">
<!-- Event handlers are defined in openaction script: -->
<!--
f.setAction('MouseUp', 'this.zoomType = zoomtype.fitW;');
// Release the mouse button, Fit window width to PDF viewer
f.setAction('MouseEnter', 'var f_me = this.getField(\'chkButton\'); if(f_me) f_me.fillColor = color.red;');
// Put pointer in range, Change background to red
f.setAction('MouseDown', 'var f_md = this.getField(\'chkButton\'); if(f_md) f_md.fillColor = color.blue;');
// Press mouse button, Change background to blue
f.setAction('MouseExit', 'var f_mxt = this.getField(\'chkButton\'); if(f_mxt) f_mxt.fillColor = color.yellow;');
// Pointer moves out of range, Change background to yellow
-->
</div>
</form>
In the following example, the calculation result is displayed by using JavaScript of PDF form in the table cell. Please refer to the contents of this document for details.