PDF In-Depth

Popping an Alert - How it's done

July 20, 2001

Advertisement
Advertisement
 

Yesterday I promised that we would talk a bit about how to put up dialogs from PDF forms based on user action. Here, the key is to know a little bit about the App Object, which is one of the objects Adobe defined, on top of core JavaScript, in Acrobat 4.0. Space doesn't permit an exhaustive discussion of the App Object here. The important thing for now is to note that if you want to do dialogs at runtime, you'll need to get familiar with App Object methods.

The alert() method takes one mandatory argument (the string that you want the user to see) plus up to two optional arguments. There is also a response() method for two-way communication, which we'll get to in a minute.

To call the alert method, you do something like:

i = app.alert("Are you sure you want overnight shipping? You live in 

Russia.", 2, 2); 

This line of code, exactly as shown, will pop an alert showing the Are you sure... text, with a warning icon and two response buttons, labelled Yes and No.

Sample alert window

The first numeric argument specifies the kind of icon to show. There are four possibilities:

0 = Error icon1 = Warning icon2 = Question icon3 = Status icon

These icons differ by operating system, as you might expect. On the Macintosh, the Zero icon is a stop sign with a hand in it; icons 1 and 2 are the same as shown above; and icon 3 is the profile view of the little cartoon-guy face, an icon that's been around since the Lisa (circa 1983).

The second numeric argument gives you a change to specify the types of buttons you want in your dialog. The default (zero) is an OK button and nothing else. The values 1, 2, and 3 correspond (in turn) to OK and Cancel, Yes and No, or Yes and No and Cancel.

The Alert Return Value

You may have noticed that app.alert() returns a numeric value. This will be one of the following:

0 = Error1 = OK2 = Cancel3 = No4 = Yes

In other words, if you specify a button group (see above), you can determine which type of button the user pressed by examining the return value from app.alert(). Pretty handy.

Will just the popup suffice?

It's nice to be able to pop an alert when a user seems to be entering incorrect data, has made a nonsensical choice, etc. But sometimes, an alert isn't really enough. Sometimes you need to be able to ask the user a specific question, and analyze (or maybe just stash) his answer. We'll talk about how to do that another time.

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.