HTML Forms : Java Glossary
home H words local find no local find frame, full screen Google search web for topic jump to footer translate with Babelfish 2008-03-30 by Roedy Green ©1996-2008 Canadian Mind Products
Go to : punctuation 0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z (all)
Forms
A form lets the user fill in the blanks, then send just the data to the server. It does not do any validation. That all must be handled by the server. A more advanced validation system is called XFORMS.

Here is a typical form:




Male
Female

Here is the HTML to generate it:

In this case the forms sends its data to a locally running test echoserver waiting for input on port 8081. What gets sent to the server looks something like this, 640 bytes of header followed by the payload:

The parameters arrive after a set of standard header fields separated from the by a blank line. The datafields are urlencoded, e.g. space appears as %40. Servlets have method for decoding and parsing all this information. Had I not ticked the sendAds checkbox the &sendAds=yes would be missing entirely.

In English that message means:
firstname=Francois Marie
lastname=d’Arouet Voltaire
email=voltaire@mindprod.com
sex=Male
sendAds=yes

The method can be either GET for short idempotent queries or POST for more complex ones. You can embed more elaborate HTML formatting commands inside the <form… </form> sandwich. The name fields identify the data to the server. the id fields help link together a label with its data field.

FORM Combo

Here is a combo, where you are allowed to select any combination of allergies:

Shift-Click to select each of your allergies:

Here is how you generate it:

To turn on the option to allow multiple choices, some older browsers would have you code plain multiple instead of multiple="multiple" and to mark an option as selected, selected instead of selected="selected". selected="selected" is the new idiotic XHTML-compatible way of specifying a boolean field option. Here is typically what gets sent back to the server:

In English this says:
patient=Roedy Green
Allergies= cat hair & milk

Note how the allergies field gets sent more than once, once for each selected value.

<optgroup can group <option. This results is a collapsed list of possibilities, making a long list more compact and easy to navigate.

Forms don’t have the equivalent of a Java JTable. The best you can do is use a giant radio button, or a checkbox on each row, to select a row, then have the server resend that row as a single record. Alternatively, you can put the selection into a giant <select <option list. You could also create a link per row and have that display the selected row by itself. Similarly you can cobble together ways to delete one or multiple records.

Form tags may not be nested, though they may appear either inside or enclosing a table.

FORMs and JavaScript

You can add some JavaScript calls to fields in your form for validation using the onsubmit and onclick attributes.
If the expression returned is true, the submit proceeds.

For some fancy tricks dynamically changing the GET url on the fly and dynamically changing the name of the fields and dynamically adding extra decorative fields, look at the source for search. I have not yet figured out how to pull off the same stunts for POST without using an Applet.

CSS
FORMS
FORMS: specification
HTML 4.01 Specifications: current HTML Standard
HTML Cheat Sheet

CMP_homejump to top
CMP logo
feedback Please email your feedback for publication, errors, omissions, broken/redirected link reports
and suggestions to improve this page to Roedy Green : feedback email
made with CSS
HTML Checked!
ICRA ratings logo
mindprod.com IP:[65.110.21.43]
Your face IP:[38.103.63.16] The information on this page is for non-military use only.
You are visitor number 1. Military use includes use by defence contractors.
You can get a fresh copy of this page from: or possibly from your local J: drive (Java virtual drive/Mindprod website mirror)
http://mindprod.com/jgloss/htmlforms.html J:\mindprod\jgloss\htmlforms.html