Chapter 15. Forms and Form ElementsAs we've seen in examples throughout this book, the use of HTML forms is basic to almost all JavaScript programs. This chapter explains the details of programming with forms in JavaScript. It is assumed that you are already somewhat familiar with the creation of HTML forms and with the input elements that they contain. If not, you may want to refer to a good book on HTML.[1] The client-side reference section of this book lists the HTML syntax along with the JavaScript syntax for forms and form elements; you may find these useful for quick reference. Submit button (or unless it has only a single text input field and allows the user to press the Return key as a shortcut for submission). With JavaScript, on the other hand, a Submit button is never necessary (unless the JavaScript program is working with a cooperating server-side program, of course). With JavaScript, a form can have any number of push buttons with event handlers that perform any number of actions when clicked. In previous chapters, we've seen some of the possible actions that such buttons can trigger: replacing one image with another, using the location property to load and display a new web page, opening a new browser window, and dynamically generating a new HTML document in another window or frame. As we'll see later in this chapter, a JavaScript event handler can even trigger a form to be submitted. As we've seen in examples throughout this book, event handlers are almost always the central element of any interesting JavaScript program. And the most commonly used event handlers (excluding the event handlers of the Link object) are those used with forms or form elements. This chapter introduces the JavaScript Form object and the various JavaScript objects that represent form elements. It concludes with an example that illustrates how you can use JavaScript to validate user input on the client before submitting it to a server-side program running on the web server. |
•
Table of Contents
•
Index
•
Reviews
•
Examples
•
Reader Reviews
•
Errata
JavaScript: The Definitive Guide, 4th Edition
By
David Flanagan
Publisher
: O'Reilly
Pub Date
: November 2001
ISBN
: 0-596-00048-0
Pages
: 936
Slots
: 1
This fourth edition of the definitive reference to
JavaScript, a scripting language that can be embedded
directly in web pages, covers the latest version of the
language, JavaScript 1.5, as supported by Netscape 6 and
Internet Explorer 6. The book also provides complete
coverage of the W3C DOM standard (Level 1 and Level 2),
while retaining material on the legacy Level 0 DOM for
backward compatibility.