PDF In-Depth

JavaScript - Response Dialogs, An interactive session

March 06, 2002

Advertisement
Advertisement
 

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.

Related Products at PDF Store

XpdfViewer

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

PDFlib TET

Reliably extract text from any PDF file with this library/component. TET makes available the text co... View full product details
Download free demo

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

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