PDF In-Depth

JavaScript - Response Dialogs, An interactive session

March 06, 2002


In a web form, there are plenty of ways to get user input. But that's not what we're talking about here. We're not talking about normal user input to the form fields. We're talking about a question-and-answer mini-session that transcends normal form data entry. I like to think of the response dialog, which is a method of the App Object, as in

replyString = app.response("Did you mean to say that?",nil,nil);

as a mechanism to let the programmer get special additional information from the user. The extra information might be a clarification, a password, or almost anything you want that isn't covered by the form's regular fields. We've already seen that the extra information entered into a response dialog can even be extra JavaScript code, which can be executed after it is entered!

If you are accustomed to regular browser-based JavaScript, the PDF response() method is exactly analogous to the prompt() method of Netscape JavaScript.

Sending E-mail from a Response Dialog

To round out our discussion of the response() method, we're going to take a look at one more example. This time, we're going to let the user enter an e-mail address into the response dialog's text area, then we're going to send an e-mail containing the contents of the Remarks field of a hypothetical form to that address.

address = app.response("Enter an e-mail address.","SEND E-MAIL","");if (address) 

 {   cmdLine = "mailto:" + address;   

this.submitForm(cmdLine,true,false,"Remarks"); }

First we put up a response dialog to get an address from the user, which we store in a variable called (what else?) address. Then we check to see if that variable contains anything before proceeding on. (If the user cancels out of the response dialog, address will be nil.) We construct a mailto command line, then call the submitForm() method on our form.

The submitForm() method takes four arguments. The first is the URL to submit to. We use a mailto URL. The second argument is a Boolean indicating where our data are to be sent as HTML or as FDF. True means FDF; false means URL encoded HTML. The third argument, a Boolean, indicates whether all the field data will be sent, or something less. We use False to indicate something less. Finally, the fourth argument is a string that (given a False third argument) tells which field or fields to send. We want to send whatever is in the Remarks field.

Note that this example doesn't check the e-mail address to see if it is valid, something you should probably do in a real-world application.

This is actually a very nonstandard way to send form data, but we use it here just for illustrative purposes. (And anyway, it doesn't automatically dismiss the form.) As always, feel free to play with the code and experiment. That's the best way to learn.

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

Five visions of a PDF Day

In the world of PDFs or as we like to say Planet (of) PDF, a year isn't a real PDF year without an intense few days of industry knowledge sharing.

May 15, 2018
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.


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.