19Scripting Forms
WHAT'S IN THIS CHAPTER?
- Understanding form basics
- Text box validation and interaction
- Working with other form controls
WROX.COM DOWNLOADS FOR THIS CHAPTER
Please note that all the code examples for this chapter are available as a part of this chapter's code download on the book's website at www.wrox.com/go/projavascript4e
on the Download Code tab.
One of the original uses of JavaScript was to offload some form-processing responsibilities onto the browser instead of relying on the server to do it all. Although the web and JavaScript have evolved since that time, web forms remain more or less unchanged. The failure of web forms to provide out-of-the-box solutions for common problems led developers to use JavaScript not just for form validation but also to augment the default behavior of standard form controls.
FORM BASICS
Web forms are represented by the <form>
element in HTML and by the HTMLFormElement
type in JavaScript. The HTMLFormElement
type inherits from HTMLElement
and therefore has all of the same default properties as other HTML elements. However, HTMLFormElement
also has the following additional properties and methods:
acceptCharset
—The character sets that the server can process; equivalent to the HTMLaccept-charset
attribute.-
action
—The URL to send the request to; equivalent to the HTMLaction
attribute. elements
—AnHTMLCollection
of all controls in the form.enctype
—The encoding type of the request; equivalent to the HTMLenctype
attribute. ...
Get Professional JavaScript for Web Developers, 4th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.