O'Reilly logo

Dreamweaver 8: The Missing Manual by David Sawyer McFarland

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Validating Forms

It can be frustrating to look over feedback that's been submitted via a form on your Web page, only to notice that your visitor failed to provide a name, email address, or some other piece of critical information. That's why, depending on the type of form you create, you might want to make certain information mandatory.

For instance, a form used for subscribing to an email newsletter isn't much use if the would-be reader doesn't type in an email address for receiving it. Likewise, if you need a shipping address to deliver a brochure or product, you'll want to be sure that the visitor included his address on the form.

Luckily, Dreamweaver provides a behavior—a ready-made JavaScript program—that accomplishes this exact task. Called Validate Form, this Dreamweaver behavior alerts visitors when they haven't filled out a form properly. You can specify that a particular field can't be left blank, or that it must contain numbers only, or that it must contain a proper email address. If someone attempts to submit the form without the correct information, a small dialog box pops up identifying the mistake. No more blank forms!

Unfortunately there's a built-in limitation to this Dreamweaver behavior: you can only validate text fields. In other words, you can't check to see whether someone clicked a particular checkbox or made a selection from a pull-down menu. Nor can you see if she chose a file to upload or clicked a radio button. (For some more advanced solutions, see the box ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required