Changes

Jump to navigation Jump to search
859 bytes added ,  08:14, 2 April 2015
example for setting default values with JS
* [http://www.adobe.com/devnet/acrobat/javascript.html JavaScript documentation at Adobe’s]
* [http://help.adobe.com/livedocs/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/wwhelp/wwhimpl/js/html/wwhelp.htm?href=JS_Dev_Tools.72.1.html&accessible=true JavaScript API Reference for Acrobat 9]
 
== Examples ==
 
=== Setting a default value ===
 
Here we set a date field to the current date on opening the document.
Additionally we have a button that can hide/show a form field.
 
<texcode>
\starttext
\setupinteraction [state=start]
 
\startJSpreamble
var d = new Date();
var df = this.getField("CurDate");
df.value = util.printd("dd.mm.yyyy", d);
 
function toggleField(){
var f = this.getField("CurDate");
f.display = ! f.display;
}
\stopJSpreamble
 
% this button makes no sense for the example, but in MkIV we need one \goto,
% otherwise we get no JS into the PDF
\goto{toggle}[JS(toggleField)]
\blank
 
\setupfield[shortString][reset,horizontal][height=5mm, width=50mm, frame=off, bottomframe=on]
\definefield[CurDate][line][shortString][][JavaScript should replace this text with the current date]
 
Current date: \field[CurDate]
 
\stoptext
</texcode>
=Fields=

Navigation menu