PDF In-Depth

Forms - The Importance of Initial Conditions

January 20, 2001

Advertisement
Advertisement
 

In programming, things that are left in an unknown state are dangerous. That's why it's usually a good idea to initialize variables with sane values as soon as they are created (and sanity-check incoming argument values before using them). But beginning programmers can't be expected to know this stuff. Yet, it seems like an awful lot of people who are using JavaScript in PDF forms are (how shall we say?) inexperienced programmers.

I encountered a good example of this last week. A form designer, desperate to the point of tears (almost), wrote to me to beg for help with a form problem. The form would load okay, and would accept the user's (textual) input into the first text field, but as soon as the field lost focus, an error alert would pop, saying something about an incorrect value. No format scripts were being applied, however, so it was a bit mysterious (at first) as to why the text field wouldn't accept ordinary text without complaining.

It soon developed that the alert went away if I turned off "Auto-Calculate Field Values" (in Tools:Forms). This meant that a distant numeric field (with a script that was being triggered by the auto-calc) was the source of the problem. I noticed that all the numeric fields had default values of 0.00 (which was not entirely rational, given some of the field names).

I didn't have to dig very much further. The calculate script for the final numeric field on the page had a division of one field value by another field value. All you had to do to trigger the script was enter anything into any text field and tab to the next field. Since all values on the page started out at zero, this set up an automatic zero-divided-by-zero situation. Error city.

Prevention is better than cure

So let that be a lesson. First, whenever dividing by a variable, either add a tiny value to the denominator to keep it from being zero, or (better) put a conditional around the division to check for the denominator being zero. Secondly (and more important, arguably), intialize your form fields to rational values. Don't just leave them blank or zero. If you do, you don't know what kind of nonsense might happen.

PDF In-Depth Free Product Trials Ubiquitous PDF

Debenu Quick PDF Library

Get products to market faster with this amazing PDF developer SDK. Over 900 functions and an equally...

Download free demo

Back to the past, 15 years ago! Open Publish 2002

Looking back to 2002, it's amazing how much of the prediction became a reality. Take a read and see what you think!

September 14, 2017
Platinum Sponsor





Search Planet PDF
more searching options...
Planet PDF Newsletter
Most Popular Articles
Featured Product

Debenu PDF Aerialist

The ultimate plug-in for Adobe Acrobat. Advanced splitting, merging, stamping, bookmarking, and link control. Take Acrobat to the next level.

Features

Adding a PDF Stamp Comment

OK, so you want to stamp your document. Maybe you need to give reviewers some advice about the document's status or sensitivity. This tip from author Ted Padova demonstrates how to add stamps with the Stamp Tool along with related comments.