Acrobat Forms - Execute javascript on document open

This is a simple trick to run a javascript code while opening an Acrobat Form. I use it very often in server side generated forms to change the required flag based on fields value.

You need to add a new document level javascript with this code.

var opened = false;

function onOpen() {

    if(!opened) {

        // Code to be executed on document open

        opened = true;



You can add a document level javascript from Advanced > Document Processing > Document JavaScripts in Acrobat 9 and from Tools > JavaScript > Document JavaScript in Acrobat 10