Click Here!
home account info subscribe login search My ITKnowledge FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

Platinum Edition Using HTML 4, XML, and Java 1.2
(Publisher: Macmillan Computer Publishing)
Author(s): Eric Ladd
ISBN: 078971759x
Publication Date: 11/01/98

Bookmark It

Search this book:
 
Previous Table of Contents Next


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:

  <BUTTON>
  <INPUT>
  <LABEL>
  <SELECT>
  <TEXTAREA>

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 Data

After 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 Encoding

When 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 user’s 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.


Storing Encoded URLs

As you learned in the previous discussion of URL encoding, packaging form data into a single text string follows a few simple formatting rules. Consequently, you can fake a script into believing that it is receiving form data without using a form. To do so, you simply send the URL that would be constructed if a form were used. This approach can be useful if you frequently run a script with the same data set.

Suppose, for example, you frequently search the Web index Yahoo! for new documents related to XML. If you are interested in checking for new documents several times a day, you could fill out the Yahoo! search query each time. A more efficient way, however, is to store the query URL as a bookmark. Each time you select that item from your bookmarks, a new query generates as if you had filled out the form. The stored URL looks like the following:

http://search.yahoo.com/bin/search?p=XML


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 Methods

You 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 used—either GET or POST—is stored in an environment variable called REQUEST_METHOD and, based on that, the data should be read in one of the following ways:

  If the data is sent by the GET method, the input stream is stored in an environment variable called QUERY_STRING. As noted previously, this input stream usually is limited to about one kilobyte of data. This is why GET is losing popularity to the more flexible POST.
  If the data is submitted by the POST method, the input string waits on the server’s input device, with the available number of bytes stored in the environment variable CONTENT_LENGTH. POST accepts data of any length, up into the megabytes, although it is not yet very common for form submissions to be that large.

Creating Forms with Authoring Tools

Composing 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, it’s 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.


Previous Table of Contents Next


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.