please dont rip this site

JavaScript: The Definitive Guide

Previous Chapter 17 Next
 

17. Forms and Form Elements

Contents:
Forms in CGI and JavaScript
The Form Object
Form Elements
Form Element Names and Values
Naming Forms and Form Elements
Form Verification Example

As we've seen in examples throughout this book, the use of HTML forms is basic to almost all web programs, whether implemented with CGI, JavaScript, or a combination of the two. This chapter explains the details of programming with forms in JavaScript. It is assumed that you already are at least 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] In addition, the reference section of this book lists the HTML syntax as well as JavaScript syntax for forms and form elements; you may find these listings helpful as well.

[1] Such as HTML: The Definitive Guide, by Chuck Musciano and Bill Kennedy, published by O'Reilly & Associates.

17.1 Forms in CGI and JavaScript

If you are already familiar with CGI programming using HTML forms, you may find that things are done somewhat differently when forms are used with JavaScript. In the CGI model, a form, and the input data it contains is "submitted"--sent to the web server--all at once. The emphasis is on processing a complete "batch" of input data and dynamically producing a new web page in response. With JavaScript, the programming model is quite different. In JavaScript programs, the emphasis is not on form submission and processing but instead on event handling. Forms and the input elements they contain each have event handlers that JavaScript can use to respond to user interactions with a form. If the user clicks on a checkbox, for example, a JavaScript program can receive notification through an event handler, and might respond by changing the value displayed in some other element of the form.

With CGI programs, an HTML form can't be useful unless it has a Submit button (or unless it has only a single text input field and allows the user to strike 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 CGI program, of course). With JavaScript, your forms 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 a button can trigger: replacing one image with another, using the location property to load and display a new web page, opening a new browser window, or dynamically generating a new HTML document in another window or frame. As we'll see later in this section, 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 used with forms or form elements. The following subsections introduce the JavaScript Form object, and the various JavaScript objects that represent form elements. The section concludes with an example that illustrates how you can use JavaScript to validate user input on the client before submitting it to a CGI program running on the web server.


Previous Home Next
Other Image Techniques Book Index The Form Object

HTML: The Definitive Guide CGI Programming JavaScript: The Definitive Guide Programming Perl WebMaster in a Nutshell

file: /Techref/language/java/script/definitive/ch17_01.htm, 6KB, , updated: 2019/10/14 15:00, local time: 2024/12/28 09:36,
TOP NEW HELP FIND: 
3.21.12.122:LOG IN

 ©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?
Please DO link to this page! Digg it! / MAKE!

<A HREF="http://sxlist.com/TECHREF/language/java/script/definitive/ch17_01.htm"> [Chapter 17] Forms and Form Elements</A>

After you find an appropriate page, you are invited to your to this massmind site! (posts will be visible only to you before review) Just type a nice message (short messages are blocked as spam) in the box and press the Post button. (HTML welcomed, but not the <A tag: Instead, use the link box to link to another page. A tutorial is available Members can login to post directly, become page editors, and be credited for their posts.


Link? Put it here: 
if you want a response, please enter your email address: 
Attn spammers: All posts are reviewed before being made visible to anyone other than the poster.
Did you find what you needed?

 

Welcome to sxlist.com!


Site supported by
sales, advertizing,
& kind contributors
just like you!

Please don't rip/copy
(here's why

Copies of the site on CD
are available at minimal cost.
 

Welcome to sxlist.com!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .