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.

Related Products at PDF Store

Nitro PDF Professional

Nitro PDF Professional, your PDF creation and editing product. Priced at $99, Nitro PDF Pro is the m... View full product details
Download free demo

XpdfViewer

This ActiveX control (OCX) provides a PDF file viewer component, enabling developers to add PDF view... View full product details
Download free demo

Adobe? Acrobat? & PDF Software

The No.1 PDF and Acrobat software store for tools to create, edit and publish PDF files. Get Nitro P... View full product details
Download free demo

PDF In-Depth Free Product Trials Ubiquitous PDF

Nitro PDF Professional

the perfect PDF product for business and enterprise, combining an extremely competitive price with a...

Download free demo

XpdfViewer

This ActiveX control (OCX) provides a PDF file viewer component, enabling developers to add PDF viewing...

Download free demo

Ubiquitous PDF: PDF eBooks-Library

If you are looking for a good store of PDF content, you could do a lot worse than visiting eBooks-Library.com...

September 03, 2009
Search Planet PDF
more searching options...







Download PDF Creator

Download The Best of Planet PDF volume 2
Planet PDF Newsletter
Most Popluar Articles
Features

Collating PDFs using JavaScript

Despite the numerous benefits, there can be potential issues with the conversion of paper documents into electronic archives. When scanning paper pages into PDF, it's possible to end up with the odd- and even-numbered pages in separate PDF files. It can be very time-consuming to collate them manually, but there is an easier way. Sean Stewart explains.

Featured Product

BCL easyPDF SDK

BCL easyPDF SDK is a set of PDF Programming Libraries designed specifically to help Software Developers / Programmers build and deploy enterprise class PDF applications for corporate wide PDF...

Platinum Sponsor
Create & Edit PDF - Nitro PDF Software

ARTS PDF

Silver Sponsors

PDF-Tools enfocus

QuickPDF: The Unrivaled PDF Developer Toolkit