|
To access the contents, click the chapter and section titles.
Platinum Edition Using HTML 4, XML, and Java 1.2
When you tab out of a form field that has focus, the field is said to blur. You can execute a script when a blur event occurs by setting onblur equal to the name of the script you want to run. onfocus and onblur can be used with the following HTML form tags:
Additionally, the <INPUT>, <SELECT>, and <TEXTAREA> tags can take the onselect and onchange event handlers that launch scripts when the field is selected or changed, respectively. All these form event handlers are useful for invoking JavaScript functions that validate the data in the form field. Chapter 21 introduces you to the scripting techniques you can employ to perform the validation tests. Passing Form DataAfter a user enters form data and clicks a Submit button, the browser does two things. First, it packages the form data into a single string, a process called encoding. Then it sends the encoded string to the server by either the GET or POST HTTP method. The next two sections close out the chapter by providing details on each of these steps. URL EncodingWhen a user clicks the Submit button on a form, the browser gathers all the data and strings it together in NAME=VALUE pairs, each separated by an ampersand (&) character. This process is called encoding. It is done to package the data into one string that is sent to the server. Consider the following HTML code: <FORM ACTION=http://www.server.com/cgi-bin/process_it.cgi METHOD=POST> Favorite color: <INPUT TYPE=TEXT NAME=Color> Favorite movie: <INPUT TYPE=TEXT NAME=Movie> <INPUT TYPE=SUBMIT> </FORM> If a users favorite color is blue and his favorite movie is Titanic, his browser creates the following data string and sends it to the CGI script: Color=blue&Movie=Titanic If the GET method is used instead of POST, the same string is appended to the URL of the processing script, producing the following encoded URL: <http://www.server.com/cgi-bin/process_it.cgi?Color=blue&Movie=Titanic> A question mark (?) separates the script URL from the encoded data string.
Further encoding occurs with data that is more complex than a single word. Such encoding replaces spaces with the plus character and translates any other possibly troublesome character (control characters, the ampersand and equal sign, some punctuation, and so on) to a percent sign, followed by its hexadecimal equivalent. Thus, the following string: I love HTML! becomes: I+love+HTML%21 HTTP MethodsYou have two ways to read the form data submitted to a CGI script, depending on the method the form used. The type of method the form usedeither GET or POSTis stored in an environment variable called REQUEST_METHOD and, based on that, the data should be read in one of the following ways:
Creating Forms with Authoring ToolsComposing HTML forms is another one of those daunting tasks that faced early content developers. Trying to keep all your <INPUT> tags and their NAMEs straight in your head can often get frustrating. And now that the form tags are expanding and becoming increasingly complex, its more important than ever to have access to an authoring tool that can assist you with the task of creating a form. This section looks at the forms support you get from Microsoft FrontPage 98, Allaire HomeSite, and Adobe PageMill.
|
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement. |