Here is a typical form:
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.
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: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.
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.
![]() |
and suggestions to improve this page to Roedy Green : | ||
| Canadian Mind Products | |||
| 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 | ||