Fields That Trigger Fields – The watch() method

On one of the discussion boards, somebody posted a request asking how a user selection in a combo box could be made to alter a global, and then all the other fields in the form would adjust their values based on the value in the global. This would ordinarily be a problem that you could solve quite easily with JavaScript’s built-in watch() method, which every object inherits from the generic Object object. The watch() method allows you to assign a callback function (of your own design) to any property of any object, so that whenever any instruction or event causes the property in question to be altered, your callback is called automagically.

There’s only one problem. The watch() method, although present in Acrobat JavaScript, doesn’t work correctly (at least under Acrobat 4.05 for Mac). It causes the property that’s being ‘watched’ to become undefined. Also, the oldval argument to the callback function doesn’t contain anything after that, for obvious reasons. (The callback always gets three parameters, called id, oldval, and newval. See any good JavaScript book for details.) So far, I haven’t found any workaround. This is apparently another one of those things that will (maybe) be fixed in the next major upgrade of Acrobat.

If anybody out there has found a way to make the watch() method work correctly, I’d be grateful to see a PDF form with code that shows it working. Post it to the Planet PDF Forum at

Noteworthy JavaScript Book

From time to time people ask me if I know of any really good JavaScript books. I usually recommend David Flanagan’s JavaScript, the Definitive Guide for a heavyduty reference (it’s outstanding) or Negrino and Smith’s Visual QuickStart book on JavaScript for an easy beginner-level introduction. Now I’ve added a third book to the list, which I can recommend to anyone who needs (how shall I say?) a broader overview of the scope and possible uses of JavaScript. Nigel McFarlane’s Instant JavaScript (Wrox) includes discussions of server-side JavaScript, security issues, connection points with Java, and (in one nicely done chapter) troubleshooting and debugging. McFarlane is one of few authors who distinguishes properly between core JavaScript, ECMAscript, browser extensions, and server extensions. On the down side, the book’s index is weak; the methods of the built-in objects (Array, Date, Math) are not discussed adequately (for this, you’ll still need Flanagan); and there is no mention of PDF per se. (But then again, no book out there mentions PDF JavaScript.) However, the reference sections in the back of the book are noteworthy, the writing style is terse without being dry, and for $24.95 list ($19.99 if you order online), it’s not going to break anyone’s budget. I wouldn’t necessarily recommend it as your first or only book on JavaScript. But as a second or third book, it’s good, because it will take your knowledge a step beyond where all the other JavaScript books bring leave you off. You’ll get a well-rounded look at the language and what it is capable of in a variety of

You May Also Like

About the Author: Kas Thomas

Leave a Reply