Skip to Main Content
Professional, JavaScript® for Web Developers, Second Edition
book

Professional, JavaScript® for Web Developers, Second Edition

by Nicholas C. Zakas
January 2009
Intermediate to advanced content levelIntermediate to advanced
836 pages
21h 30m
English
Wrox
Content preview from Professional, JavaScript® for Web Developers, Second Edition

Chapter 13. Scripting Forms

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 HTML accept-charset attribute.

  • action — The URL to send the request to; equivalent to the HTML action attribute.

  • elements — An HTMLCollection of all controls in the form.

  • enctype — The encoding type of the request; equivalent to the HTML enctype attribute.

  • length — The number of controls in the form.

  • method — The type of HTTP request to send, typically "get" or "post"; equivalent to the HTML method attribute.

  • name — The name of the form; equivalent to the HTML name attribute.

  • reset() — Resets all form fields to their default values.

  • submit() — Submits the form.

  • target — The name of the window to use for ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Professional: JavaScript® for Web Developers, Third Edition

Professional: JavaScript® for Web Developers, Third Edition

Nicholas C. Zakas
JavaScript: Best Practice

JavaScript: Best Practice

James Kolce, Moritz Kroger, Ivan Curic, Samier Saeed, Jeff Mott, M. David Green, Craig Buckler

Publisher Resources

ISBN: 9780470227800Purchase book